Conversion Tool mencoder application in Linux

Source: Internet
Author: User
In Linux, The Conversion Tool mencoder application-general Linux technology-Linux technology and application information. The following is a detailed description. The Office has a Linux machine, 24 hours boot, and the configuration is not low (P4-3.0E), than I am now using the CY4-2.4GHZ is much better, idle is also idle, early want to use it, I have heard of mencoder in Linux and have always wanted to try it. recently I tried to convert rmvb TV series to mpeg2 and xvid. The purpose of this conversion is to cut a disk and put it on my BBK DVD player. The effect is good and the speed is fast. I searched on the Internet before turning it around. There are very few articles on mencoder in Linux. so I wrote out the process and communicated with you.

Install mencoder
Mencoder is used with mplayer and is difficult to install. You can download the compiled rpm package from the following website:
Http://www.mplayerhq.hu/homepage/design7/news.html
However, if you want to output mp3 audio and xvid videos, you still need to compile the source code package and download the lame mp3 library and xvid library in advance. The required libraries include:
Lame-libs-devel-3.96.1-2
Lame-libs-3.96.1-2
Xvidcore-devel-1.0.2-1
Xvidcore-static-1.0.2-1
Xvidcore-1.0.2-1
Find the appropriate rpm package on the Internet, and then install it with rpm-I.

After these libraries are installed, decompress the mplayer source code package and run it. /configure will be automatically configured according to your system conditions, with support for mp3 and xvid. then execute make to compile. I compiled it smoothly.

In addition, we also need to download the decoding codecs of mplayer, which is also downloaded from the above website. My post is the updated all, over 10 MB in the 2005.4.12 version, download and decompress the package to the/usr/lib/codecs directory. there are some in this bag. dll file. the acm file also contains. so files. With these codecs, the popular audio and video formats can basically be read.

Use mencoder to convert rmvb to mpeg2 and xvid
Currently, I only use mencoder to convert rmvb To mpg and avi. It can do a lot more.
The audio and video encoding of my TV series rmvb is:
Video: 139 Mb, 453 Kbps, 23.0 fps, resolution: 512*412 (), RV40 = RealVideo 9
Audio: 13.55 Mb, 44 Kbps, 22050Hz, 2 channels, 0x0 = RealAudio 8, cook-29

Convert rmvb to the mpg file of the mp2 audio mpeg2video video:

Mencoder 01. rmvb-oac lavc-lavcopts acodec = mp2: abitrate = 64-ovc lavc-lavcopts vcodec = mpeg2video: vbitrate = 600: vpass = 1-ofps 24000/1001-of mpeg-o 01.mpg

Convert rmvb into an avi file of the mp3 audio xvid video:
Mencoder 01. rmvb-oac mp3lame-lameopts preset = 64-ovc xvid-xvidencopts bitrate = 600-of avi-o 01.avi

-Specifies the audio encoding library used by oac.
-Specifies the video encoding library used by ovc.
-Xxxopts: Specify the option Parameter

Because the rmvb file has a tablet group header, you can use the ER editor to cut the previous 20 seconds. This may be the reason. For all files converted into mp3 audio, the sound is not synchronized with the screen for several minutes at the beginning; mp2 audio is normal.
I can't tell the difference between the transferred mpg2 file and the small Japanese file. The transfer of a set in over 40 minutes is about 11 minutes, turn around 1 hour with little Japanese (run mencoder machine is P4E-3.0GHZ, run small Japanese machine is CY4-2.4GHZ); turn into xvid encoding speed a little slower, about 13 minutes.

I use mencoder to convert rm and rmvb (real) to mpeg, and use libavcodec. files that can be read by mplayer can usually be transferred. The common parameters are as follows:
Mencoder input file. rmvb-o output file. mpg-oac lavc-ovc lavc {detailed parameter}

The above lavc uses libavcodec to determine the codec used to suppress sounds and images. For {detailed parameter}, You need to select a dvd, vcd, or svcd as required.

I changed the content of the table and added the corresponding parameters to the table. to press the mpg, you only need to query the table in the required format, then add the parameter speed from left to right, and then add the following extra part. The mencoder Manual also provides several advanced options, but these advanced options are only useful when converting to a dvd.

Note the following parameters when pressing the mpg:
Format, Resolution, FPS, Sample Rate, Aspect, V. Codec, V. Bitrate, A. Codec, A. Bitrate,
For example, svcd of pal:
Format Resolution FPS Sample Rate, Aspect V. Codec V. Bitrate A. Codec A. Bitrate,
Pal svcd 576x576 25 44100Hz 4: 3 MPEG-2 2600 kbps MP2 384 kbps

The options for meoncder to control these parameters are:
Format Resolution FPS Sample Rate Aspect V. Codec V. Bitrate A. Codec A. Bitrate
-Of-mpegopts-vf scale-ofps-srate-af {-lavcopts aspect: vcodec: vbitrate: acodec: abitrate}

Because these parameters Aspect V. codec V. bitrate. codec. bitrate is controlled by lavcopts, so I changed the table provided in the mencoder manual to the location so that they can be grouped together for ease of searching.

Here is an example of pal svcd. Add parameters from left to right based on the table, and add the extra buffer control parameters.
Mencoder 01. rmvb-o 01.mpg-oac lavc-ovc lavc-of mpeg-mpegotps format = xvcd-vf scale = 576: 576, harddup-ofps 25-srate 44100-af lavcresample = 44100-lavcopts aspect = 4/3: vcodec = mpeg2video: vbitrate = 980: acdec = mp2: abitrate = 192: keyint = 15: vrc_buf_size = 917: vrc_maxrate = 2500

Note that scale = 576: 576 and aspect = 4/3 are /.

It seems complicated. In fact, these parameters must be adjusted only during the test. When you find the appropriate parameter, alias will be enough.

My mencder parameter table:
Http://rendercow.com/mencoder.xls

The problem now is how to read the rm header file, determine the rm bit rate and other information, and select a low bit rate during conversion (vcd standard 1150 video and audioaudio seem a little large) to reduce the size of the converted file.

Added x264 encoding support
Adding x264 encoding support costs a little bit. Because of the bug in mplayer1.0pre7, an error occurred while compiling to a ve_x264.c file,
To compile the latest source code, I will download the version. I will also download the x264 source code to generate libx264.a,
My latest r281 version from the doom9 Website: x1__rev281_src.7z
The nasm compilation compiler is required to compile x264. if the system is not installed, install the next rpm package.

First install and compile x264, decompress the package, run sh./configure, and then make. After compilation, run:
Make install
The installation of x264 is complete!

Then compile and install mplayer. The steps are the same as before. Execute configure to automatically determine that x264 support is added, and then execute make to compile.

I tried converting an rmvb into a x264 video mp2 audio. It took 40 minutes to complete the conversion, which was much longer than other encodings.

Test script:
#! /Bin/sh

MP2_64 = "-oac lavc-lavcopts acodec = mp2: abitrate = 64"
MPG2 = "-ovc lavc-lavcopts vcodec = mpeg2video: vbitrate = 500-of avi"
XVID = "-ovc xvid-xvidencopts bitrate = 500-of avi"
MPG4 = "-ovc lavc-lavcopts vcodec = mpeg4: vbitrate = 500-of avi"
X264 = "-ovc x264-xforwarencopts bitrate = 500-of avi"

Time mencoder 01. rmvb ${MP2_64 }$ {MPG2}-o mpg2.avi
Time mencoder 01. rmvb ${MP2_64 }$ {MPG4}-o mpg4.avi
Time mencoder 01. rmvb ${MP2_64 }$ {XVID}-o xvid. avi
Time mencoder 01. rmvb ${MP2_64 }$ {X264}-o x264.avi

Run Time (user Time ):
Mpg2 8m13. 586 s
Mpg4 8m23. 287 s
Xvid 16m41. 351 s
X264 40m37. 554 s

Now I have transferred a lot of rmvb and will discuss some questions.
1. some rmvb decoding problems. for example, when I turn to <really want to fall in love>, there are several sets of outgoing charts like green lines, and the same problem occurs with mplayer. in windows, everything works normally.

2. Some rmvb cannot be converted according to the original resolution. For example, the original resolution is 512x384, but after mencoder is executed, it is displayed as follows:

VDec: vo config request-352x288 (preferred csp: Planar I420)

Then I switched to the 352x288 resolution. I used mplayer to display the same prompt information, which only allowed the 352x288 resolution. I feel that there is still a bug in the real decoder in linux.

3. if mp3 is used for audio, there will be many problems when the transferred files are stored on my BBK993 drive, such as no sound or non-synchronous voice. if the video is decoded using xvid, it is good to zoom in on the player in most cases, but occasionally the screen is instantly jittery. It is normal to play on the computer. so far, there has not been any problem with the combination of mpeg2video for audio mp2 videos. What is lacking in the US is that mpeg2's image quality is worse than that of xvid at the same bit rate.

Modify the mencoder so that the output mpeg4 video can be played on the BBK player.

You can use the lavc decoder of mencoder to compress mpeg4 videos, but you cannot play back the mpeg4 videos on my BBK player after the disk is engraved. After analysis, it is found that the mpeg4 video is pressed by mencoder, it indicates that the video stream string is FMP4, And the DVD player only recognizes xvid and divx. If the FMP4 in the file header is changed to DIVX, DX50, or XVID, the video can be played normally on the DVD player.

Modify source code:
Find the following two lines in the libmp codecs/ve_lavc.c file:
Else if (! Strcasecmp (lavc_param_vcodec, "mpeg4 "))
Mux_v-> bih-> biCompression = mmioFOURCC ('F', 'M', 'P', '4 ');

Change FMP4 to DIVX and recompile it.

Today, I posted a short HD wm9 video clip from Microsoft's website: the_magic_of_flight_7w.wmv.
Compress the data to rmvb, xvid, mpeg4, x264, mpeg2, and re-sample the data to 640x352. The low bit rate of-KBS is tested,
The main conclusion is as follows:

1. the image quality of x264 is not as good as that of xvid and mpeg4.
2. the image quality of xvid is similar to that of mpeg4. I don't know the difference.
3. rmvb is better than xvid and mpeg4.
4. The worst mpeg2.

Conclusion 1 is unexpected, or it may be that the selected parameters are not suitable, and the default parameters are used.

Test script:
#! /Bin/sh
MP2_64 = "-oac lavc-lavcopts acodec = mp2: abitrate = 64"
MPG2 = "-ovc lavc-lavcopts vcodec = mpeg2video: vbitrate = 300-of mpeg"
XVID = "-ovc xvid-xvidencopts bitrate = 300-of avi"
MPG4 = "-ovc lavc-lavcopts vcodec = mpeg4: vbitrate = 300-of avi"
X264 = "-ovc x264-xforwarencopts bitrate = 300-of avi"

Time menc the_magic_of_flight_71_wmv ${MP2_64 }$ {XVID}-vf scale = 640: 352-ofps 30-o xvid. avi
Time menc the_magic_of_flight_71_wmv ${MP2_64 }$ {X264}-vf scale = 640: 352-ofps 30-o x0000t. avi
Time menc the_magic_of_flight_71_wmv ${MP2_64 }$ {MPG4}-vf scale = 640: 352-ofps 30-o mpg4.avi
Time menc the_magic_of_flight_71_wmv ${MP2_64 }$ {MPG2}-vf scale = 640: 352-ofps 30-o mpg2.avi

Running time:
Xvid 1m56. 731 s
X2 64 3m15. 652 s
Mpg4 1m6. 293 s
Mpg2 1m5. 601 s

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.