视频转成flv格式

1 篇文章 0 订阅

这里讲一下重要的:
1.用到两个工具,一个是ffmpeg.exe,另一个是mencoder.exe
ffmpeg最新版本的下载地址:http://ffdshow.faireal.net/mirror/ffmpeg/
Mencoder新版本的下载地址:http://www5.mplayerhq.hu/MPlayer/releases/win32/

这里有一个重点,网上的文章都没讲到,所以造成有些人运行后没反应,原因是上面路径的下载,有很多版本,不同的版本可能个别参数不同,而网上的文章所用的参数都是用很早的版本写的,所以会造成运行后因参数错误而没有效果
简单处理是:把网上参数在cmd命令行执行一下,这时命令行会报哪个参数错误,把它删了即可!

2.判断处理成功与失败或是进度是否完成,从异步获取的输出信息判断[包括获取原视频的宽与高]
这里重点在两个委托事件中,详情见以下几行代码

 private  void StartProcess(string tool)
 3         {
 4             StartProcess(tool, false);
 5         }
 6         private  void StartProcess(string tool,bool onlyCheckInfo)
 7         {
 8             System.Diagnostics.Process p = new System.Diagnostics.Process();
 9             p.StartInfo.FileName = tool;
10             p.StartInfo.Arguments = commandPara;
11             p.StartInfo.UseShellExecute = false;
12             p.StartInfo.RedirectStandardInput = true;
13             p.StartInfo.RedirectStandardOutput = true;
14             p.StartInfo.RedirectStandardError = true;
15             p.StartInfo.CreateNoWindow = false;
16             p.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_OutputDataReceived);
17             if (onlyCheckInfo)//只检测文件是否可转换与获到内部宽与高
18             {
19                 p.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_CheckInfoDataReceived);
20             }
21             else
22             {
23                 p.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_ErrorDataReceived);
24             }
25             //开始执行 
26             try
27             {
28                 p.Start();
29                 p.BeginOutputReadLine();
30                 p.BeginErrorReadLine();
31                 p.WaitForExit();
32             }
33             catch (Exception err)
34             {
35                 Console.WriteLine(err.Message);
36             }
37             finally
38             {
39                 p.Close();
40             }
41         }
42         void p_CheckInfoDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
43         {
44             if (!string.IsNullOrEmpty(e.Data))
45             {
46                 if (e.Data.Contains("Stream") && e.Data.Contains("Video:"))//设置原视频窗口大小作为flv视频的宽与高
47                 {
48                     Match match = Regex.Match(e.Data, @", (\d+)x(\d+)");
49                     if (match != null)
50                     {
51                         videoWidth = match.Groups[1].Value;
52                         videoHeight = match.Groups[2].Value;
53                     }
54                 }
55                 else if (e.Data.Contains("could not find codec parameters"))//ffmpeg转换失败
56                 {
57                     isCanChangeToFlv = false;
58                     Program.SetDataBase(id, 1, count + 1);
59                 }
60             }
61 
62         }
63 
64          void p_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
65         {
66             if (!string.IsNullOrEmpty(e.Data))
67             {
68                 if (e.Data.Contains("video:") && e.Data.Contains("muxing overhead"))//ffmpeg转换完成
69                 {
70                     Program.SetDataBase(id, 2, count + 1);
71                     Console.WriteLine("转换完成");
72                 }
73                 Console.WriteLine(e.Data);
74             }
75             
76         }
77 
78          void p_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
79         {
80             if (!string.IsNullOrEmpty(e.Data))
81             {
82                 if (e.Data.Contains("Writing index"))//mencoder转换完成
83                 {
84                     Program.SetDataBase(id, 2, count + 1);
85                     Console.WriteLine("转换完成");
86                 }
87                 //else if (e.Data.Contains("Exiting"))//mencoder转换失败
88                 //{
89                 //    Console.WriteLine("转换失败");
90                 //}
91                 Console.WriteLine(e.Data);
92             }
93         }


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值