Converted into a video format flv

Recently completed a small Demo, to share!
Above it gave me two days to complete this little feature
after I spent half a day in the time information from the network po everywhere, and spent a long time debugging code, success, finally With a little rule of thumb the following:

Here to talk about important:
1. use two tools, one is ffmpeg.exe, and the other is mencoder.exe
ffmpeg Download the latest version: http://ffdshow.faireal.net/mirror/ffmpeg/
Mencoder new version the Download: http://www5.mplayerhq.hu/MPlayer/releases/win32/

There is a focus on online articles have not talked about, it caused no reaction Some people run because the path to download the above, there are many versions, different versions may be different individual parameters, and online articles are used by the parameters written with an early version, and will therefore result after running due to parameter error without the effect of
simple treatment is: the online cmd command line parameters in it, then the command line parameter which will report an error, it can be deleted!

2. The judge handling success and failure or progress is complete, output information obtained from the asynchronous judgment [including access to the width and height of the original video]
Here commission focused on two events, as detailed in the following lines of code

Code
 1 
 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)//Only detects whether the document can be converted to the internal width and height eligible 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 is          {
44 is  IF  ( ! String ) .IsNullOrEmpty (e.data) 45             { 46 is IF  (e.Data.Contains ( " Stream " &&  e.Data.Contains ( " Connections Video: " )) // set the original size of the video window as wide and high 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("not the Find the Parameters CODEC could " )) // ffmpeg conversion failed 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 conversion is complete 83                
                 {
84                      Program.SetDataBase (ID,  2 , COUNT  + . 1 ); 85                     Console.WriteLine ( " conversion completed " ); 86                 } 87 // the else IF (e.Data.Contains ( "the Exiting")) // MEncoder conversion failed 88 // { 89 //     Console.WriteLine ( "conversion failed"); 90 // } 91 
 
 
                 
                 
                 
                 
                 Console.WriteLine(e.Data);
92             }
93         }
94 
95 


Talk about the focus of this article, please combined with the network and other articles to this article!

Reproduced in: https: //my.oschina.net/secyaher/blog/274107

Guess you like

Origin blog.csdn.net/weixin_34010949/article/details/91967094