2011-07-20 15 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に関連付けられたファイルです。まず、ファイル が存在するかどうかを確認します。