C# Winfrom使用ffmpeg转换视频格式

  //视频转码
        private void VideoConverter()
        {
            filelen = 0;
            ListView lv = listView1;
 
            for (int i = 0; i < lv.Items.Count; i++)
            {
                if (lv.Items[i].SubItems[3].Text != "已完成")
                {
                    Process p = new Process();
 
                    p.StartInfo.FileName = path + "ffmpeg";
 
                    //p.StartInfo.FileName = path + "ffmpeg.exe";
 
                    p.StartInfo.UseShellExecute = false;
                    string srcFileName = "";
                    string destFileName = "";
                    string newFileName = "";
                    string mbgs = "." + comboBox2.SelectedItem.ToString();
 
                    srcFileName = lv.Items[i].SubItems[1].Text;
                    newFileName = lv.Items[i].SubItems[0].Text.Split('.')[0];
 
                    destFileName = "\"" + label3.Text + "\\" + newFileName + DateTime.Now.ToString("yyyyMMddhhmmss");
 
                    p.StartInfo.Arguments = "-i " + srcFileName + " -y  -vcodec h264 -b 500000 " + destFileName + mbgs + "\"";    //执行参数
 
                    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();//释放资源
                    setState(i);//更新文件状态
                    filelen += 1;//已转换文件数量
                }
            }
 
        }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
下面是压缩前后的文件大小及画质对比
在这里插入图片描述
压缩前
在这里插入图片描述
压缩后
在这里插入图片描述

C# Winfrom使用ffmpeg转换视频格式(新)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值