zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C#实现 ffmpeg视频转码、播放

c# 实现 视频 播放 FFMPEG 转码
2023-09-27 14:20:25 时间

主要是转码的操作过程,能够实现了从相机获取的MP4转换成普通播放器播放的MP4格式;

//转码方法
        private void Test1()
        {

            Process p = new Process();


            p.StartInfo.FileName = path +"ffmpeg.exe";

            p.StartInfo.UseShellExecute = false;
            string srcFileName = "";
            string destFileName = "";
            srcFileName = path + "InitVideo1.mp4";

            destFileName = path + "InitVideo.mp4";

            p.StartInfo.Arguments = "-i " + srcFileName + " -y  -vcodec h264 -b 500000 " + destFileName;    //执行参数

            p.StartInfo.UseShellExecute = false;  不使用系统外壳程序启动进程
            p.StartInfo.CreateNoWindow = true;  //不显示dos程序窗口

            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.StartInfo.UseShellExecute = false;

            p.Start();

            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            p.BeginErrorReadLine();//开始异步读取



            p.WaitForExit();//阻塞等待进程结束

            p.Close();//关闭进程

            p.Dispose();//释放资源
        }