// 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)
{
}