Ffmpg conversion FLV

Source: Internet
Author: User

// Convert to FLV

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;
}

 

// Generate a PIC at the same time

Public static void getimagefromvideo (string fromname, string imgname, string tooldir)
{
Try
{

PROCESS p = new process (); // create an external call thread
P. startinfo. windowstyle = processwindowstyle. hidden;
P. startinfo. filename = tooldir + @ "\ ffmpeg.exe"; // httpcontext. Current. server. mappath (@ "tool/ffmpeg.exe"); // call externalProgramAbsolute path

P. startinfo. arguments = @ "-I" + fromname + "-y-F image2-T 0.001-s 150x150" + imgname; // parameter (here is the FFMPEG parameter)
P. startinfo. useshellexecute = false; // do not use the operating system shell program to start the thread (it must be false. For details, see msdn)
P. startinfo. redirectstandarderror = true; // write the error output of an external program to the standarderror stream. (Note that all output information of FFmpeg is an error output stream, standardoutput cannot capture any messages...
P. startinfo. createnowindow = false; // do not create a process window
P. startinfo. windowstyle = processwindowstyle. hidden;

P. Start (); // start the thread
P. waitforexit (); // wait for completion
P. standarderror. readtoend (); // start synchronous reading
P. Close (); // close the process
P. Dispose (); // release resources

}
Catch (exception ERR)
{

}
Finally
{

}

}

 

 

 

 

String tooldir = @ "D: \ works \ tool \";
Try
{


//. FLV |. wmv
System. Io. fileinfo Fi = new system. Io. fileinfo (@ "D: \ works \... Avi ");

If (Fi. exists)
{
String saveflv = Fi. fullname. Replace (Fi. Extension, ". FLV ");
String saveimage = Fi. fullname. Replace (Fi. Extension, ". jpg ");

Videohelper. videoconvertflv (Fi. fullname, saveflv, "300x300", tooldir );
Videohelper. getimagefromvideo (saveflv, saveimage, tooldir );
}
}
Catch (exception ex)
{
}

 

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.