Using FFmpeg to merge video in C #

Source: Internet
Author: User

First put the latest ffmpeg.exe in the debug path, http://www.ffmpeg.org/download.html

Then call this method

   Public voidCombinemp4withouttxt (stringSTRMP4A,stringSTRMP4B,stringStroutmp4path) {Process P=NewProcess ();//establishing an external calling threadp.StartInfo.FileName = System.Windows.Forms.Application.StartupPath +"\\ffmpeg.exe";//the absolute path of the external program to invoke            stringStrarg ="- I. concat:\ ""+ strmp4a +"|"+ strmp4b +"\ "-vcodec copy-acodec copy"+ Stroutmp4path +"- y"; P.startinfo.arguments=Strarg; P.startinfo.useshellexecute=false;//start thread without using the operating system shell (must be false, see MSDN for details)P.startinfo.redirectstandarderror =true;//Write the external program error output to the StandardError stream (this must be noted that all output information of the ffmpeg is an error output stream, with StandardOutput is not capturing any messages ...) This is the experience I have spent for 2 months ... mencoder is captured with StandardOutput)P.startinfo.createnowindow =true;//do not create process windowP.errordatareceived + =NewDatareceivedeventhandler (Output);//the event generated by the external program (here is the ffmpeg) output stream, here is the process of transferring the stream to the following method, please refer to MSDNP.start ();//Start ThreadP.beginerrorreadline ();//start Asynchronous Readp.WaitForExit ();//blocking wait process endP.close ();//Close ProcessP.dispose ();//Freeing Resources}

This code is exception-throwing processing, please add your own code

   Private void Output (object  sendprocess, Datareceivedeventargs output)        {            if (!  String.IsNullOrEmpty (output. Data)                {// processing method ...             }        }

which

STRMP4A represents a pre-video physical path such as D:\A.MP4,STRMP4B, which represents the physical path of a video after a physical path such as D:\b.mp4,stroutmp4path represents a composite video, such as D:\AB.mp4.

If the effect of the composition is not ideal, such as only merging the former video, or only after the combination of sound, please follow the fmpeg.exe cmd instruction (please do your own Baidu command), the test is complete to modify this line

   String Strarg = "-I concat:\" "+ strmp4a +" | "+ strmp4b +" \ "-vcodec copy-acodec copy" + Stroutmp4path + "-y"

Using FFmpeg to merge video in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.