Use FFMPEG in Asp.net (the uploaded video is converted to the FLV format and an image is taken)

Source: Internet
Author: User
Tags flv file
Protected   Void Button#click ( Object Sender, eventargs E)
{
String Ffmpegarguments = @" -I d: \ Li Ge. wmv-AB 56-ar 22050-B 500-R 15-s 320x240 D: \ Li Ge. FLV " ;
// Processstartinfo info = new processstartinfo ("D:/FFMPEG", ffmpegarguments );
// Process. Start (Info );

PROCESS p = New Process (); // The process class has a startinfo atomicity. This is processstartinfo class, which includes some attention and Methods. Below we use its attention:
P. startinfo. filename = " D:/FFMPEG/ffmpeg.exe " ; // SetProgramName
P. startinfo. Arguments = ffmpegarguments; // Set the number of dynamic rows in the program
P. startinfo. useshellexecute = False ; // Use of Shell
P. startinfo. redirectstandardinput = True ; // Redirect to ingress
P. startinfo. redirectstandardoutput = True ; // Redirect to outbound
P. startinfo. redirectstandarderror = True ; // Redirect zookeeper outbound
P. startinfo. createnowindow = True ; // Display window for setting no parameters
P. Start (); // Operation
// P. standardinput. writeline (ffmpegarguments ); // You can also use this method to export the command to be executed.
// P. standardinput. writeline ("exit "); // But remember to add exit, or else the next line of program will become available when the program crashes.
}

/**/ /// Convert video (AVI, mov, etc.) to FLV format
/// </Summary>
/// <Param name = "fromname"> Converted video file </Param>
/// <Param name = "exportname"> Name of the converted FLV File </Param>
/// <Param name = "exportname"> Video size </Param>
/// <Returns> </returns>
Public String Videoconvertflv ( String Fromname, String Exportname, String Widthandheight)
{
String FFmpeg = @" D: \ FFMPEG \ ffmpeg.exe " ;
System. Diagnostics. processstartinfo startinfo =New System. Diagnostics. processstartinfo (FFMPEG );
Startinfo. windowstyle = system. Diagnostics. processwindowstyle. hidden;
// Startinfo. arguments = "-I" + server. mappath (fromname) + "-AB 56-ar 22050-B 500-R 15-s" + widthandheight + "" + server. mappath (exportname );
Startinfo. Arguments = " -I " + Fromname + " -AB 56-ar 22050-B 500-R 15-S " + Widthandheight +" " + Exportname;
Try
{
System. Diagnostics. process. Start (startinfo );
Return Exportname;
}
Catch (Exception ERR)
{
Return Err. message;
}
}

/**/ /// <Summary>
/// Capture a frame from the video screen as an image
/// </Summary>
/// <Param name = "videoname"> Video file PIC/Guiyu. mov </Param>
/// <Param name = "widthandheight"> The image size is 240*180. </Param>
/// <Param name = "cuttimeframe"> The start time of the screenshot, for example, "1" </Param>
/// <Returns> </returns>
Public String Getpicfromvideo ( String Videoname, String Widthandheight,String Cuttimeframe)
{

String FFmpeg = @" C: inetpubwwwrootdemopic fmpeg.exe " ;
String Picname = server. mappath (guid. newguid (). tostring (). Replace ( " - " , "" ) + " . Jpg " );
System. Diagnostics. processstartinfo startinfo = New System. Diagnostics. processstartinfo (FFMPEG );
Startinfo. windowstyle = system. Diagnostics. processwindowstyle. hidden;
Startinfo. Arguments = " -I " + Server. mappath (videoname) + " -Y-F image2-SS " + Cuttimeframe + " -T 0.001-S " + Widthandheight + " " + Picname;
Try
{
System. Diagnostics. process. Start (startinfo );
Return Picname;
}
Catch (Exception ERR)
{
Return Err. message;
}
}

 

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.