Asp. NET downgrade using FFmpeg and mencoder to realize video conversion screenshot

Source: Internet
Author: User

Recently to do a video playback system, the use of ffmpeg and mencoder two tools, check some information, found that the information is quite a bit, but it is a little messy, I myself from the beginning to tidy up a bit, and you share:

1, FFmpeg realize video (avi,wmv and other formats) converted to FLV format:

/// <summary>    ///convert video to FLV/// </summary>    /// <param name= "FileName" >the path to the uploaded video file (original file)</param>    /// <param name= "Playfile" >The path of the converted file (network play file)</param>    /// <returns>success: Return 1 failure: 0</returns>     Public intFchangefilevir (stringFileName,stringplayfile) {        //High video width after conversion        stringWidthoffile =" the"; stringHeightoffile =" -"; //get Ffmpeg.exe path, path configured in Web. config, such as: <add key= "FFmpeg" value= " E:\aspx1\ffmpeg.exe"/>        stringFFmpeg =Server.MapPath (Publicmethod.ffmpegtool); if((! System.IO.File.Exists (ffmpeg)) | | (!System.IO.File.Exists (fileName))) {            return 0; }        //get (. flv) file relative path        stringFlv_file = System.IO.Path.ChangeExtension (Server.MapPath (Playfile),". flv"); //establish the FFmpeg processSystem.Diagnostics.ProcessStartInfo Filestartinfo =NewSystem.Diagnostics.ProcessStartInfo (ffmpeg); //set the background to run without displaying the windowFilestartinfo.windowstyle =System.Diagnostics.ProcessWindowStyle.Hidden; //run the parameters, which are combined into the parameters required by the Ffmpeg.exe file, where the command is ffmpeg 0.4. Over 9 Debug Pass//ffmpeg-i F:\01.wmv-ab 56-ar 22050-b 500-r 15-sFilestartinfo.arguments ="- I."+ FileName +"-ab 56-ar 22050-b 500-r 15-s"+ Widthoffile +"x"+ Heightoffile +" "+Flv_file; Try        {            //Start ConversionSystem.Diagnostics.Process.Start (Filestartinfo); }        Catch        {            return 0; }        return 1; }

2, MEncoder realize video (avi,wmv and other formats) converted to FLV format:

    /// <summary>    ///convert video to FLV/// </summary>    /// <param name= "FileName" >the path to the uploaded video file (original file)</param>    /// <param name= "Playfile" >The path of the converted file (network play file)</param>    /// <returns>success: Return 1 failure: 0</returns>     Public intMchangefilevir (stringFileName,stringplayfile) {        //High video width after conversion        stringWidthoffile =" the"; stringHeightoffile =" -"; //get Mencoder.exe path, path configured in Web. config, such as: <add key= "mencoder" value= " E:\aspx1\mencoder.exe"/>        stringTool =Server.MapPath (Publicmethod.mencodertool); //determine if mencoder tools and files exist        if((! System.IO.File.Exists (ffmpeg)) | | (!System.IO.File.Exists (fileName))) {            return 0; }        //get (. flv) file relative path        stringFlv_file = System.IO.Path.ChangeExtension (Server.MapPath (Playfile),". flv"); //Build a tool processSystem.Diagnostics.ProcessStartInfo Filestartinfo =NewSystem.Diagnostics.ProcessStartInfo (tool); //set up background runFilestartinfo.windowstyle =System.Diagnostics.ProcessWindowStyle.Hidden; //Operating ParametersFilestartinfo.arguments =" "+ Vfilename +"- o"+ Flv_file +"-of lavf-lavfopts I_CERTIFY_THAT_MY_VIDEO_STREAM_DOES_NOT_USE_B_FRAMES-OAC mp3lame-lameopts ABR:BR=56-OVC LAVC- Lavcopts VCODEC=FLV:VBITRATE=200:MBD=2:MV0:TRELL:V4MV:CBP:LAST_PRED=1:DIA=-1:CMP=0:VB_STRATEGY=1-VF scale="+ Widthoffile +":"+ Heightoffile +"-ofps 12-srate 22050"; Try        {            //Start ConversionSystem.Diagnostics.Process.Start (Filestartinfo); }        Catch        {            return 0; }        return 1; }

3, FFmpeg realization video content:

    //video, filename video address, imgfile image address     Public stringCatchimg (stringFileName,stringimgfile) {        //using the FFmpeg capture chart        stringFFmpeg =Server.MapPath (Publicmethod.ffmpegtool); //Picture name        stringflv_img = Imgfile +". jpg"; //Picture Size        stringFlvimgsize =publicmethod.sizeofimg; //establish the FFmpeg processSystem.Diagnostics.ProcessStartInfo Imgstartinfo =NewSystem.Diagnostics.ProcessStartInfo (ffmpeg); //running in the backgroundImgstartinfo.windowstyle =System.Diagnostics.ProcessWindowStyle.Hidden; //Process Parameters//Ffmpeg-i input.flv-y-F image2-ss 10.11-t 0.001-s 240x180 catchimg.jpg;Imgstartinfo.arguments ="- I."+ FileName +"-y-f image2-ss 2-vframes 1-s"+ Flvimgsize +"   "+flv_img; Try        {            //start to grab a pictureSystem.Diagnostics.Process.Start (Imgstartinfo); //sleep, wait to finish, set on DemandSystem.Threading.Thread.Sleep ( the); }        Catch        {            return ""; }        //        if(System.IO.File.Exists (flv_img)) {returnflv_img; }        return ""; }

The principle is very simple, in fact is to use System.Diagnostics.Process call FFmpeg and mencoder the two ready-made tools to work, the key is to pass the parameters, mainly to see the ffmpeg and mencoder use of the familiar degree.

Asp. NET downgrade using FFmpeg and mencoder to realize video conversion screenshot

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.