视频转码h264格式,并将元数据放入第一帧

c# 利用ffmpeg进行开发。主要为了方便转后的视频在网页中通过ckpaly播放,并压缩视频文件节省存储空间。将元数据放入视频第一帧可以 不用缓冲太多就可以秒播。

核心代码

string name = f.Name;
                string tmp_name = Guid.NewGuid() + ".mp4";
                string[] spr = name.Split('.');//然后根据.分割文件名称
                string minzhm = spr[spr.Length - 1];//获取最后一个,这样就获取到了文件的后缀名
                string[] allowExtension = { "avi", "mp4", "mov", "f4v", "mpg", "mpeg", "flv" };//视频的常用格式
                int index = Array.IndexOf(allowExtension, minzhm.ToLower());
                if (Array.IndexOf(allowExtension, minzhm.ToLower()) == -1)//然后把后缀名统一改为小写,比较一下是否存在,存在的话,表示是视频
                    continue;
                fmain.SetDataRichTextBox_rtb0(f.Name + " 开始转换mp4 H264格式...\n");
                String Command = " -i " + '"' + insrc + "\\" + f.Name + '"' + "  -y " + watermark + " -vcodec h264 -b 500000  " + '"' + outsrc + "\\" + f.Name + '"';
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = ffmpeg_src;
                p.StartInfo.Arguments = Command;
                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(Error_Output);
                p.OutputDataReceived += new DataReceivedEventHandler(Output);
                p.Start();
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                //p.BeginOutputReadLine();
                p.BeginErrorReadLine();//开始异步读取  
                p.WaitForExit();//阻塞等待进程结束  
                p.Close();//关闭进程  
                p.Dispose();//释放资源
                //SetDataRichTextBox_rtb0(f.Name + " 格式转换完成,开始提取元数据...\n");
                fmain.SetDataRichTextBox_rtb0(f.Name + " 格式转换完成,开始提取元数据...\n");
                Command = insrc + "\\" + f.Name + " " +outsrc + "\\" + f.Name;
                p = new System.Diagnostics.Process();
                p.StartInfo.FileName = qtfast_src;
                p.StartInfo.Arguments = Command;
                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(Error_Output);
                p.OutputDataReceived += new DataReceivedEventHandler(Output);
                p.Start();
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                p.BeginErrorReadLine();//开始异步读取  
                p.WaitForExit();//阻塞等待进程结束  
                p.Close();//关闭进程  
                p.Dispose();//释放资源

                fmain.SetDataRichTextBox_rtb0(f.Name + " 提取元数据成功!end\n");


程序界面



链接:https://pan.baidu.com/s/1_odHa3_2OZA0Ut0JRWONSw 密码:g3di

csdn下载:https://download.csdn.net/download/tbzhang30/10408687

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值