How to create a thumbnail using the ffmpeg.exe
I am trying to create a thumbnail of an .wmv video. I had tried the following code :
Guid id = Guid.NewGuid();
string thumbpath, thumbname, videopath;
string thumbargs, inputfile;
thumbpath = "C:\\Users\\Tom\\Desktop\\picture gallery\\";
thumbname = thumbpath + id.ToString() + ".jpg";
videopath = "C:\\Users\\Tom\\Desktop\\video gallery\\";
inputfile = Videopath + id.ToString() + ".wmv";
thumbargs = "-i " + inputfile + " -vframes 1 -ss 00:00:07 -s 150x150 -f image2 " + thumbname;
Process thumbproc = new Process();
thumbproc = new Process();
thumbproc.StartInfo.FileName = "C:\\Users\\Tom\\Desktop\\ffmpeg\\ffmpeg.exe";
thumbproc.StartInfo.UseShellExecute = false;
thumbproc.StartInfo.CreateNoWindow = false;
thumbproc.StartInfo.RedirectStandardOutput = false;
try
{
thumbproc.Start();
if (thumbproc != null)
{
thumbproc.Close();
}
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Visible = true;
}
I am accessing the video which is stored in a folder "Video gallery". The problem with my solution is that it was showing the error "unable to find suitable output format for ffmpeg 'gallery\69b77a48-1b3c-4ce7-8c5a-fba10af5d9b1.jpg' " when I run the solution.
But if I remove the spaces in the path of thumbnai开发者_C百科l (picturegallery or videogallery) then it works fine.
Please tell me is there any problem with my "thumbargs" or anything i missing in my code.
thumbproc.StartInfo.Arguments = thumbargs;
You forgot to initialize arguments.
Follow this: Convert Video to FLV and Create Thumbnails from file using C#
protected void Convert(string fileIn, string fileOut, string thumbOut)
{
try
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = ffmpegPath;
proc.StartInfo.Arguments = "-i " + fileIn +
" -ar 22050 -ab 32 -f flv -s 320×240 -aspect 4:3 -y " + fileOut.Split('.')[0] +
".flv";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.WaitForExit();
Ref: HOW-TO:Create video-preview thumbnails manually
Command - Line
ffmpeg -itsoffset -4 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
Check your code
Guid id = Guid.NewGuid();
, after generating new GUID, is any file associated with new GUID.. first check that file exists or not.
精彩评论