How to call FFMPEG in C # to convert the video format

Source: Internet
Author: User
Tags stack trace
My goal is to call FFMPEG conversion. the AVS file is. there is no problem with FLV files and parameters. I can run the command line to successfully convert the video format. now I write it as a function in Program In the call, there is a problem :(

Public int convertvideotoflv ()
{
Int re= 999;

PROCESS p = new process (); // create an external call thread
P. startinfo. filename = @ "F: \ FLV \ FFMPEG. rev1_64 \ ffmpeg.exe"; // call the absolute path of an external program
P. startinfo. Arguments = "-y-I sss. AVS-AB 56-B 500 k programout. FLV"; // parameter (FFMPEG parameter)
P. startinfo. useshellexecute = false; // do not use the operating system shell program to start the thread

P. startinfo. redirectstandardinput = true;
P. startinfo. redirectstandardoutput = true;

P. startinfo. redirectstandarderror = true; // write the error output of an external program to the standarderror stream.

 

P. startinfo. createnowindow = false; // do not create a process window
P. errordatareceived = new datareceivedeventhandler (output); // transfer the stream processing process to the output
P. Start (); // start the thread
P. beginerrorreadline (); // start asynchronous reading

P. waitforexit (); // blocking waits for the process to end
P. Close (); // close the process
P. Dispose (); // release resources

Return re;
}

After debugging, it is found that the program runs normally, but the actual conversion is not performed. I am not very familiar with process usage. Please kindly advise what went wrong!
User reply: You didn't use the OS shell to start the program. I think so. You set it to use the OS shell to start the program.
The conversion process may require video decoding or something !!
Reply: Help LZ top
The user replied: "/" server error in the application.
To redirect an IO stream, the useshellexecute attribute of the Process object must be set to false.

Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information to learn about this error andCodeDetails of the error source.

Exception details: system. invalidoperationexception: to redirect Io streams, the process object must set the useshellexecute attribute to false.

If this parameter is set to true, an error is returned...
User reply: I finished the process and found that the ffmpeg.exe process was running when the pause was called, but the CPU was displayed as 0, and the conversion was not executed at all. Let's take a look at the cause. Thank you!
User reply: solved. It is necessary to set a working directory ~ Paste
Reply: public static string videoconvertflv (string fromname, string widthandheight, string exportname)
{

String FFMPEG = httpcontext. Current. server. mappath ("~ /FLV/ffmpeg.exe ");
String command = "-I" fromname "-y-AB 56-ar 22050-B 500-R 15-s" widthandheight "" exportname; // FLV format

 

// String command = "E: \ FFMPEG \ ffmpeg.exe-I e :\\ clibdemo \ videopath \ admin \. WMV-y-AB 56-ar 22050-B 500-R 15-s 320*240 "exportname;
System. Diagnostics. PROCESS p = new system. Diagnostics. Process ();
P. startinfo. filename = FFMPEG;
P. startinfo. Arguments = command;
P. startinfo. workingdirectory = httpcontext. Current. server. mappath ("~ /FLV /");
P. startinfo. useshellexecute = false;
P. startinfo. redirectstandardinput = true;
P. startinfo. redirectstandardoutput = true;
P. startinfo. redirectstandarderror = true;
P. startinfo. createnowindow = false;
// Start execution
P. Start ();
P. beginerrorreadline ();
P. waitforexit ();
P. Close ();
P. Dispose ();
// P. standardinput. writeline (command );
// P. standardinput. writeline ("exit ");
Return exportname;
}

Protected void button#click (Object sender, eventargs E)
{

Strfile = httpcontext. Current. server. mappath ("~ /FLV/ (dashboard). mpg ");;
Videoconvertflv (strfile, "480*360", "Zh. FLV ");
Videoconvertimg (strfile, "480*360", "zh.jpg ");
}

 

Http://hi.baidu.com/honfei/blog/item/d636cf4eabf0000cb2de0574.html

Related Article

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.