Use Mencoder to convert any video format to flv

Source: Internet
Author: User
Tags windows download flv file

Preface:

This article is my basic understanding of Mencoder. For Beginners, it may be used as a tutorial. If you have a deep research on Mencoder, please contact me. Qq: 151952789. Msn: tangyifei830217@hotmail.com.

Mencoder introduction:

Mencoder is a built-in encoding tool for Mplayer (Mplayer is an open-source player in Linux and supports playing in almost all video formats. Currently, it is available in windows and Mac versions ).

Mplayer acquisition and Configuration:

Mplayer windows download list: http://www5.mplayerhq.hu/MPlayer/releases/win32/
The list contains the version release date. You can select the latest version, or select old/to download the old version. The author uses the version of July. Download the package and decompress it to a folder.

Codecs download list: http://www5.mplayerhq.hu/MPlayer/releases/codecs/
Select windows-all -********. zip (* indicates the year, month, and day) to download all the files in the folder in the zip package, including *. dll ,*. acm ,*. ax and so on are all copied to the codecs folder under the root directory of Mplayer.

You 'd better add the mplayer.exe‑path, which is also the path of mencoder.exe to the environment variable path.

Now you can try playing a video with Mplayer. For example, a video is located at D: \ music \ APerfectMatch. wmv, you can open a cmd window and enter mplayer "D: \ music \ APerfectMatch. wmv ", feel the player from Linux, you can use the keyboard to manipulate it.

Mencoder:

For example, convert a variety of formats to the flv format (the flv format is the video format supported by flash ):

Mencoder 'e: \ test. m2p'-O' E: \ output. flv '-of lavf-lavfopts audio-oac mp3lame-lameopts abr: br = 56-ovc lavc-lavcopts vcodec = flv: vbitrate = 500: mbd = 2: mv0: trell: v4mv: White: last_pred = 3: dia = 4: cmp = 6: vb_strategy = 1-vf scale = 512:-3-ofps 12-srate 22050

Enter this line of code in the command line (Note: windows command lines do not support line breaks). Press enter to run the command. After a while, you can get a line. flv file, play it to see how it works (you can use Mplayer to play it directly ).

It is the comparison of the conversion results on my side, the original video on the left, and the converted video on the right:

Everyone will think that the quality of the converted file has dropped a lot. This is indeed the case. At the same time, we can find that the converted file has changed from 13 M to 1 M. To improve the quality, you can change vbitrate = 500 to vbitrate = 5000.

Comparison of converted results: the original video on the left and the converted video on the right:

The quality is almost the same, but at the same time, the conversion file is changed to 6 M.

Some parameters in the command are described as follows:

-O 'e: \ output. flv': indicates the path of the output file;

-Of lavf: the output file format. flv is not flv but lavf because flv belongs to libavformat;

-Lavfopts labels:-lavfopts indicates some settings for lavf. The setting content is "translate". Translated to Chinese: I'm sure, my video does not use B frames. for the conversion of flv format, it is best to add this parameter. Otherwise, an error may be reported,

-Oac mp3lame: oac = output audio codec, which is used to output the audio Encoder;

-Lameopts abr: br = 56: lame options: this parameter is specially set for the mp3lame parameter. abr: br = 56 indicates that the audio bit rate is set to 56 (bit rate: audio output per second, in kb/s );

-Ovc lavc: ovc = output video codec. The output video coder. lavc indicates one of libavcodec's video codec. The output format is one of libavformat. The coder is also one of libavcodec, for the encoders in libavodec, you can view the official Mplayer documentation;

-Lavcopts vcodec = flv: vbitrate = 500: mbd = 2: mv0: v4mv: trell: White: last_pred = 3: dia = 4: cmp = 6: vb_strategy = 1: set lavc as follows:
Vcodec = flv: Specify the video encoder as flv;
Vbitrate = 500: the specified video bit rate is 500. this parameter is very important. A large vbitrate can increase the video quality, but it will make the file much larger (refer to the parameters of the conversion tool provided by flash 8: The low quality is kb/s, the medium quality is kb/s, and the high quality is kb/s ).
Mbd: select an algorithm for the macro module. The value ranges from 0 ~ 2 The default value is 0. The larger the value, the slower the conversion, but it is advantageous in terms of quality and file size;
Mv0: compile each macro module and select the best one. It is invalid when mbd is set to 0;
V4mv: The quality is slightly increased, and the effect of mbd> 0 is more obvious;
Trell: Quantum mesh search to find the optimal encoding for every 8x8 blocks;
White service: this function can only be used with trell phase I to evaluate distorted image block encoding;
Last_pred = 3: the number of moves compared to the previous frame. The value ranges from 0 ~ 99,1 ~ 3 is more suitable. When it is greater than 3, it does not matter the quality improvement, but it will reduce the speed;
Dia = 4: mobile search range, value range:-99 ~ 6. For fast conversion,-1 is a good value. If you do not pay much attention to speed, you can consider 2 ~ 4;
Cmp = 6: The value is 1 ~ 2000. The default value is 0. Set the comparison function for moving the budget of all pixels.
Vb_strategy = 1: It is helpful for scenarios with large movements. For some videos, setting vmax_ B _frames will damage the quality, and adding vb_strategy = 1 will be better.

The above is a detailed explanation of-lavcopts, and the following describes the mencoder parameters:

-Vf scale = 512:-3:-vf indicates the video format, scale indicates scaling, 512:-3 indicates that the width is set to 512, and the height is written to-3 to maintain the aspect ratio, you can also set it to-1 or-2. If you are interested, try again. If you want to forcibly convert to a uniform size, you can directly write-vf scale = 640: 480, but I personally suggest using-3 to maintain the aspect ratio. -Vf contains the expand and crop parameters, for example,-vf scale = 512: 384, expand = 512: 384: 1, crop = 512: 384: 0: 0, expand indicates expansion, and crop indicates cropping;

-Ofps 12: The Frame Rate of the output video. Generally, it is meaningless to increase the video file size when the frame rate is high for flash playback. However, if ofps is not set properly, for example, if the frame rate of the source video is not an integer multiple of ofps, the converted video and audio may not be synchronized. It seems that this parameter can be changed to-noskip to solve this problem;

-Srate 22050: the audio sampling rate is generally 22050 or 44100.

Lavsopts settings are important for converting the flv format, and many parameters are not involved in this article. For more information, see the relevant documents. My understanding of Mencoder mainly comes from the following two articles, with few practices. If you have any mistakes in understanding and Translation, please feel free to contact me again.

References:

Mplayer official documentation, English version http://www.mplayerhq.hu/DOCS/HTML-single/en/MPlayer.html
The Linux Reviews http://linuxreviews.org/man/mencoder/

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.