Created
September 26, 2013 21:59
-
-
Save kad1r/6721178 to your computer and use it in GitHub Desktop.
Create a thumbnail image from video with ffmpeg with .net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Web; | |
namespace WebApp.HelperClass | |
{ | |
public class CreateThumbFromVideo | |
{ | |
/// <summary> | |
/// created by ~kad1r | |
/// send files without mappath | |
/// like "/video/videolink1.avi" | |
/// function puts mappath itself | |
/// download ffmpeg.exe - http://www.speedyshare.com/mRbUN/ffmpeg.rar | |
/// </summary> | |
/// <param name="file"></param> | |
/// <returns></returns> | |
public static string generateThumb(string file) | |
{ | |
string thumb = ""; | |
try | |
{ | |
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath(file)); | |
string filename = Path.GetFileNameWithoutExtension(fi.Name); | |
Random random = new Random(); | |
int rand = random.Next(1, 9999999); | |
string newfilename = "/video/" + filename + "___(" + rand.ToString() + ").jpg"; | |
var processInfo = new ProcessStartInfo(); | |
processInfo.FileName = "\"" + HttpContext.Current.Server.MapPath("/video/ffmpeg.exe") + "\""; | |
processInfo.Arguments = string.Format("-ss {0} -i {1} -f image2 -vframes 1 -y {2}", 5, "\"" + HttpContext.Current.Server.MapPath(file) + "\"", "\"" + HttpContext.Current.Server.MapPath(newfilename) + "\""); | |
processInfo.CreateNoWindow = true; | |
processInfo.UseShellExecute = false; | |
using (var process = new Process()) | |
{ | |
process.StartInfo = processInfo; | |
process.Start(); | |
process.WaitForExit(); | |
thumb = newfilename; | |
} | |
} | |
catch (Exception ex) | |
{ | |
string error = ex.Message; | |
} | |
return thumb; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOT WORKING