簡體   English   中英

如何在C#中使用ffmpeg將視頻轉換為圖像文件?

[英]how can i convert a video into image files using ffmpeg in c#?

        string inputpath = strFileNamePath;
        string outputpath = "C:\\Image\\";
        //for (int iIndex = 0; iIndex < 1000; iIndex++)
        //{
            //string fileargs = "-i" + " " + inputpath + "  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv " + outputpath + "SRT.flv";
            string fileargs = "-i" + " " + inputpath + " " + outputpath + "image.jpg";
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "C:\\Documents and Settings\\Badr\\My Documents\\Visual Studio 2008\\Projects\\Video2image2video.\\ffmpeg\\ffmpeg.exe";
            p.StartInfo.Arguments = fileargs;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();

我有此代碼,這僅創建了1張視頻圖像,我應用了一個循環,但我反復生成了初始圖像,我該如何獲取所有視頻的圖像

預先感謝

ffmpeg文檔中

您可以從視頻中提取圖像,也可以從許多圖像中創建視頻:

要從視頻中提取圖像:

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg

這將從視頻中每秒提取一個視頻幀,並將它們輸出到名為foo-001.jpeg', foo-002.jpeg'等的文件中。圖像將重新縮放以適應新的WxH值。

因此,只需更改傳遞給ffmpeg的參數,就應該啟動並運行。

嗨,當您以這種方式返回時,您想在視頻文件中拍攝圖像嗎?

 for (int i = 0; i < iImageCount; i++)
                                {

                                   string sInputVideo = Page.MapPath(...);

                                   string sImageCapture = Page.MapPath("") + "\\Videolar\\"  + ImageName+ "_" + iResim + ".jpg";

                                    ffmpeg.StartInfo.Arguments = " -i \"" + sInputVideo + "\" -s 108*100 -ss " + iImageCapture + " -vframes 1 -f image2 -vcodec mjpeg \"" + sImageCapture + "\"";
                                    ffmpeg.StartInfo.FileName = (Server.MapPath("Referanslar/ffmpeg.exe"));
                                    ffmpeg.Start();
                                    ffmpeg.WaitForExit();
                                    ffmpeg.Close();
                                    iImageCapture += 1;
                                    iResim++;
                                }

您可以通過更改來隨意拍攝照片;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM