C# 調用FFmpeg 根據圖片合成視頻

1.項目結構:異步

 

2.代碼:spa

  

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebFFmpeg
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string pathString = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            Process p = new Process();
            p.StartInfo.FileName = pathString + "\\FFmpeg\\ffmpeg.exe";
            p.StartInfo.Arguments = @"-y -r 1 -i " +
                                    pathString + @"FFmpeg\pic\img%2d.jpg -i " +
                                    pathString + @"FFmpeg\music\02.mp3 -s 800x800 -vcodec mpeg4" +
                                    pathString + @"FFmpeg\vedio\out.mp4";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.Crea teNoWindow = true;
            p.ErrorDataReceived += new DataReceivedEventHandler((s, message) => { Response.Write(message.Data); });//外部程序(這裏是FFMPEG)輸出流時候產生的事件,這裏是把流的處理過程轉移到下面的方法中,詳細請查閱MSDN
            p.Start();//啓動線程
            p.BeginErrorReadLine();//開始異步讀取
            p.WaitForExit();//阻塞等待進程結束
            p.Close();//關閉進程
            p.Dispose();//釋放資源

            Response.Write("<a href='FFmpeg/vedio/out.mp4'>下載</a>");
        }
    }
}

3.Demo 鏈接線程

  http://share.weiyun.com/581ce7da333c175841c90931fdfd17563d

相關文章
相關標籤/搜索