Use FFmpeg to turn MP4 into FLV

Source: Internet
Author: User

Recently done a small project to play the recorded MP4 video online, like open source Flash Player or HTML 5 can play. However, although MP4 is encoded in H. T, it is not playable. May be the packaging method (PS mode) is not the same. Due to the third-party device for recording, the parameter cannot be modified and can only be transcoded using the tool itself.

Ffmpeg

Online a search, found the famous FFmpeg, as if Google's YouTube backstage is also used this transcoding, a lot of domestic video player core is this. With this implementation is very simple. FFmpeg the CPU is high when transcoding, can go to 100%, do not know how to solve this problem. Transcoding as long as one instruction is on the line:

Ffmpeng.exe-i source.mp4-c:v LIBX264-CRF destination.flv

This is the simplest setting, more can go to the official website to see the detailed parameters, which-CRF is very important, is to control the quality of transcoding video, the higher the quality, the larger the file.

The range of the Quantizer is 0-51:where 0 are lossless, and is default, and are worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider to being visually lossless or nearly so:it should look the same or nearly the same as the input but it isn ' t tec Hnically Lossless.

Explanation of the official website (translation):

The range of this value is 0 to 51:0 for HD Lossless, 23 is the default value (if this parameter is not specified), and 51 has the lowest file size, but the effect is the worst.

The smaller the value, the higher the quality, but the larger the file, the recommended range of values is 18 to 28. The value 18 is visually lossless or nearly lossless, and of course does not mean that data (technically) transcoding is lossless.

Coding:

Implementation is also very simple, as long as the use of processs background transcoding on the line, see Ffmpeghelper:

1 usingSystem;2 usingSystem.Configuration;3 usingSystem.IO;4 //Referencehttps://github.com/LeafDuan/WebPrint/tree/master/WebPrint.Framework5 usingwebprint.framework;6 //Referencehttps://github.com/LeafDuan/WebPrint/tree/master/WebPrint.Logging7 usingwebprint.logging;8 9 namespaceWebPrint.CameraServer.HelperTen { One      Public classFfmpeghelper A     { -         Private Static ReadOnlyILogger Logger = Loggerhelper.getlogger (typeof(Ffmpeghelper)); -  the         Private Static stringFfmpeg -         { -             Get{returnconfigurationmanager.appsettings["FFMEPG"]; } -         } +  -         Private Static stringArgs +         { A             Get{returnconfigurationmanager.appsettings["args"]; } at         } -  -         Private Static stringFlvpath -         { -             Get{returnconfigurationmanager.appsettings["flv"]; } -         } in  -          Public Static stringDECODEMP4TOFLV (stringMP4,intTimeout =0) to         { +             varFFmpeg ="\ "{0}\"". Formatting (Ffmpeg); -             varflv = Path.Combine (Flvpath, (path.getfilenamewithoutextension (mp4)??string. Empty) +". flv"); the             varargs = Args.formatting ("\ "{0}\"". Formatting (mp4),"\ "{0}\"". Formatting (flv)); *             stringoutput, error; $             if(Timeout <=0)Panax NotoginsengTimeout =5* -* +;//timeout = 5 minutes -Processhelper.process (ffmpeg, args, timeout, outOutput outerror); the             if(!error. IsNullOrEmpty ()) +             { ALogger.error ("{0}{1}: {2}{0}". Formatting (Environment.NewLine,"FFmpeg", error)); the             } +  -             returnflv; $         } $     } -}
View Code

The implementation of the process requires skill, especially for output, error, and timeout processing. If you do not use AutoResetEvent, the process is easily stuck On error output (IO blocked). Where the time-out, do a deal, is to kill the process, so as to avoid the resource overrun and leakage (excessive ffmpeg process).

Attached: Flash recommendation

can be transcoded into HTML 5 supported by H. I, or other formats, such as FLV. To be compatible with IE6 and above browsers, only flash playback is available. Using open-source vcastr22.swf, it is possible that the project is not being maintained because of open source.

Finally, a sentence: Hope IE9 The following version of the early demise. In order to automatically scale with the window in 16:9 size, compatible with IE6, 7 css and JS is written exhausted. Because the non-professional front-end, find information are exhausted.

Use FFmpeg to turn MP4 into FLV

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.