Use FFMPEG to convert media files

Source: Internet
Author: User
The mencoder command line looks a little scary, so FFmpeg is used. In fact, most of the so-called conversion software is based on FFMPEG, and mencoder also uses FFMPEG. FFmpeg is used for mplayer organizations. So why can't many software convert some files and CODEC? This is because FFmpeg is not supported. For example, wmvv3 (wmv9) encoding and FFMPEG are not supported now. Therefore, basically all the conversion software that can be seen now is not supported. Only wmvv1 (wmv7) and wmvv2 (wmv8) are supported) decode and encode.


The following are some steps and key points: 1. Compile FFMPEG by yourself. The FFMPEG function in Ubuntu reposiroty is incomplete (mainly depends on how to compile it). For example, because libmp 3lame is not introduced, FFMPEG in Ubuntu official repository cannot encode MP3 (only encode MP2 -- MPEG 1 audio Layer 2 ). Compiling FFmpeg is very simple. Configure, make, and sudo make install will be OK. Configure is mainly used to check which support is enabled. What I did this time is:


. /Configure -- prefix =/usr -- enable-GPL -- enable-postproc -- enable-nonfree -- enable-pthreads -- enable-x11grab -- enable-libamr-Nb -- enable-libamr-WB -- enable-GPL- libfaac -- enable-libfaad -- enable-libmp3lame -- enable-libx264 -- enable-libxvid -- disable-armv5te -- disable-armv6 -- disable-armv6t2 -- disable-armvfp


Follow the command line above to install faac, faad, libmp 3lame, amrnb, amrwb, x133 .... In particular, remember to install the dev version of these packages. Only the dev version package contains header files. Here we can also see that FFMPEG does not work for every Decoder/encoder, but also relies on many other projects. For example, x264, which is made by the VLC player organization, is used for the encoder/decoder of h264.


2. Then FFmpeg is used. Media files can be easily converted, for example: FFmpeg-I HYB-wish.wav-acodec libmp 3lame-AB 192 K-AC 2 HYB-wish.mp3ffmpeg-I HYB-wish.wav-acodec libfaac-AB 192 K-AC 2 HYB-wish.aacffmpeg-I HYB-wish.wav-acodec libamr_nb-AB 12.2 K- ar 8000-Ac 1 HYB-wish-nb.amrffmpeg-I HYB-wish.wav-acodec libamr_wb-AB 23.85 K-Ar 16000-Ac 1 HYB-wish-wb.amr


Look at the manual of FFMPEG to understand the meaning of these parameters, which is very simple:-I -- input file;-acodec -- specify audio codec, use the FFMPEG-formats command to view all the file formats and CODEC;-AB -- bitrate supported by the currently compiled FFMPEG. A key must be followed by a key; otherwise, the key is invalid; -AC: specifies the number of channels;-AR: Specifies the sample rate. Note that amrnb is 8000, amrwb is 16000, and normal is 44100/48000. The last parameter is the name of the output file. FFMPEG checks the file format to be converted based on the extension. You can also use-F option to specify the output file format.


3. convert video: # convert only 14400 frames-24fps, so this is 10 minutes, that is, export FFMPEG-I mada2_hsf-_aac_24.mp4-vcodec copy-vframes 14400-acodec copy mada_hsf-_aac_24.mp4 #-S: size;-r FPS;-B bitrate; "copy" means does not convert, pure copy FFMPEG-I samsung_mpeg4_aac_30.mp4-vcodec h263-s CIF-R 30-B 496 K-acodec copy signature-I accept-vcodec h263p-R 30-B 496 K-s qvga- acodec copy audio-I samsung_mpeg4_aac_30.mp4-vcodec libx264-s qvga-R 30-B 496 K-acodec copy audio # FFMPEG-I audio-vcodec mpeg2video-s qvga-R 30-B 496 k-acodec libmp 3lame-AB 192 K-AC 2 audio-I mada_hsf-_aac_24.mp4-vcodec h263-s CIF-R 24-B 952 K-acodec copy audio-I audio-vcodec h263p-S 480X272-B 952 K-R 24-acodec copy audio-I mada_hsf-_aac_24.mp4-vcodec MPEG4-s 480X272-R 24-B 952 K-acodec copy mada_mpeg4_aac_24.mp4 # FFMPEG-I mada_h1__aac_24.mp4-vcodec mpeg2video-s 480X272-B 952 K-R 24-acodec libmp 3lame-AC 2-AB 192 K mada_mpeg2_mp3_24.mpg


Note: 1. Different codec supports different video sizes. For example, h263 does not support qvga (320x240. If it is set incorrectly, FFMPEG will prompt and print all video size supported by h263. If the parameters of the audio conversion are incorrect, FFMPEG will also print the cause and prompt information, which is very good.


2. Different file formats are also required for codec that can be placed in the file. For example, MP4 cannot be put into h263/MP3. Therefore, when it is converted to h263, all output files are 3GP. If file format is incorrect, the error message of FFmpeg is: [<file format> <function address>]: cocould not find tag ......


This is basically the case. FFmpeg is very useful, especially for converting different media files and codec. For more information about each parameter, see FFMPEG manual. However, FFMPEG still has many problems: for example, many codec still do not support it, such as wmvv3 (wmv9) and wmav3 (wma9. There are also many codec that only provide decoder, but not encoder. This is also very painful for conversion, but it is nothing for playing. There are also some bugs, such as the above command line, when converting to h263p, if the output file format is given 3GP, it will make an error saying cocould not find tag ..., in fact, 3GP can be put into h263p, and 3GP on is h263 ++/AMR. Therefore, the above is replaced by mov.


BTW: If you want to convert to WMA/WMV, as mentioned earlier, if it is wmav1, wmav2, wmvv1, wmvv2 (that is, wma7, wma8, wmv7, wmv8 ), you can use FFMPEG. However, for wmav3 and wmvv3 (wma9, wmv9), Microsoft's Windows Media Encoder can only be used. Windows Media Encoder requires that the input files are BMP, JPG, MP3, WAV, mpg, Avi, WMV, WMA, and ASF. The other files are not compatible.
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: 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.