2011-07-20 101 views
2

我正在嘗試創建.wmv視頻的縮略圖。我曾嘗試以下代碼:如何使用ffmpeg.exe創建縮略圖

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; 
    } 

我正在訪問存儲在「視頻庫」文件夾中的視頻。我的解決方案的問題是,當我運行該解決方案時,它顯示錯誤「找不到合適的輸出格式ffmpeg'gallery \ 69b77a48-1b3c-4ce7-8c5a-fba10af5d9b1.jpg'」。

但是,如果我刪除縮略圖(圖片庫或視頻圖庫)的路徑中的空間,那麼它工作正常。

請告訴我有沒有我的「thumbargs」或我的代碼中缺少的任何問題。

回答

0
thumbproc.StartInfo.Arguments = thumbargs; 

你忘了初始化參數。

+0

我加了後者。 thumbproc.StartInfo.Arguments = thumbargs;那麼我也面臨同樣的問題。 – prasad

0

關注這個: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(); 

編號: HOW-TO:Create video-preview thumbnails manually

命令 - 行

ffmpeg -itsoffset -4 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg 

檢查你的代碼Guid id = Guid.NewGuid();,產生新後GUID,是與新的GUID相關的任何文件。首先檢查文件 是否存在。