ffmpeg视频转码

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


namespace BookShop.Web.ffmpeg
{
    public partial class ffmpeg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建并启动一个新进程
            Process p = new Process();
            //设置进程启动信息属性StartInfo,这是ProcessStartInfo类,包括了一些属性和方法:
            p.StartInfo.FileName = Server.MapPath("/ffmpeg/ffmpeg.exe");       //程序名
            p.StartInfo.UseShellExecute = false;
            //-y选项的意思是当输出文件存在的时候自动覆盖输出文件,不提示“y/n”这样才能自动化
              //生成视屏中图片
            // string srcFileName = Server.MapPath("/Video/aa.avi");
            //string destFile =Server.MapPath("/Video/1.jpg");
            //p.StartInfo.Arguments = "-i " + srcFileName + " -y -f image2  -ss 53 -t 0.001 -s  600x500 " + destFile;    //执行参数


             ///视屏转码
            string srcFileName = Server.MapPath("/Video/aa.avi");
            string destFileName = Server.MapPath("/Video/a.flv");
            p.StartInfo.Arguments = "-i " + srcFileName + " -y -ab 56 -ar 22050 -b 800 -r 29.97 -s 420x340 " + destFileName;    //执行参数
            
            
            
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中
            p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
            p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
            p.Start();
            p.BeginErrorReadLine();//开始异步读取
            p.WaitForExit();//阻塞等待进程结束
            p.Close();//关闭进程
            p.Dispose();//释放资源


        }
        protected void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
         
        }
        protected void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
        { 
        
        }
    }
}

你可能感兴趣的:(asp.net)