Using MEncoder to Shrink High Def to xvid


As I've previously mentioned, I'm using a PCHDTV HD-3000 to capture High Definition ATSC transport streams. I can then use ProjectX to do basic snips and edits, as well as demux which program stream from within the transport stream I'd like to retain. Today, I'll talk about how to make MEncoder (MPlayer) shrink down your video to a handy DivX/xvid file.

Previously, I've transferred these over to another partition to use some Windows-based tools for appropriate transcoding. This is a time consuming process, but in the scope of sharing on Pure DVD - this is what works best for me. However, now I find myself transcoding down to xvid. I've found that using the MEncoder portion of the MPlayer suite of programs does the job best for me.

The command that is working best for me is as follows...

time mencoder -ovc xvid -xvidencopts bitrate=1000:profile=dxnhtntsc:par=ntsc169:aspect=720/405 -oac mp3lame -lameopts preset=medium -vf scale=720:405,pp=l5 -af volnorm=1:1.15 -o outputfile.avi inputfile.ts

...I'll explain in a little more detail.

The time command will simply print out the total time the command took, once it completes. For me, 65 minutes of HD content took about 112 minutes of transcoding time using these parameters. mencoder is obviously the name of the application to do the transcoding.

-ovc xvid tells MEncoder I'd like to work with the xvid codec. Note that the ability to do so needs to be compiled into MEncoder. In Fedora, the RPM I had installed with YUM did not include this built-in. I had to download the xvid package and recompile MEncoder. (Details below.)

-xvidencopts bitrate=1000:profile=dxnhtntsc:par=ntsc169:aspect=720/405 tells MEncoder some xvid codec parameters I'd like. In this case, I'm setting it to 1000 kbps, which is a good baseline for normal quality, resulting in about a 550 Megabyte file. Note that this is a Constant Bit Rate (CBR) setting (VBR/2-pass available in documentation for MEncoder). The profile=dxnhtntsc specifies I'd like to use a DivX compatible (via xvid) profile. This ensures I'll be able to play the file on standalone NTSC compliant hardware. There are other values for the profile setting that work for this also (see MPlayer man page). par=ntsc169:aspect=720/405 specifies aspect ratio (16:9, 720/405 = Widescreen or par=ntsc43:aspect=720/480 for 4:3 images).

-oac mp3lame -lameopts preset=medium specifies my .avi file's audio settings. In this case, I'm using the output audio codec of mp3 (via lame). I'm using the lame option of a "medium" present. This should be about 160kbps on audio. Again, note that you'll need to have support compiled into MEncoder (see below).

-vf scale=720:405,pp=l5 specifies some video filters I'd like to use. In this case, I'm downscaling from 1920x1080 to 720x405 (widescreen). This may seem redundant, but this is where the actual resizing takes place. The previous mentions of 720x405 simply tell the play what size of video to expect. pp=l5 specifies my preferred method for deinterlacing. I seem to prefer this method on non-film shows (SNL, Conan O'Brien). Some film shows on ABC and FOX arrive in a progressive format, and don't require deinterlacing. Your preference may vary depending on the show and its source.

-af volnorm=1:1.15 is my only audio filter in this example. Here, I'm using the volnorm to amplify my source. I've noticed sometimes a 5.1 downconvert can produce "faint" audio when playing on my PC, but seems normal if I'm playing it on my home DVD player. This seems to be a quick and dirty fix to allow me to have decent levels in both places. Note that I use "volnorm" which only stretches the audio waveform. The "volume" option increases everything, elevating the levels of everything, including static and noise.

Finally, -o outputfile.avi inputfile.ts specifies my output .avi file and my input transport stream.

As I mentioned, you'll need to ensure that you have a version of MPlayer/MEncoder that supports xvid and lame (MP3). To see if you're already set up...


mplayer -oac help
mplayer -ovc help

If xvid and mp3lame isn't listed, you'll need to obtain the appropriate libraries. You may already have these, and simply compile them into MPlayer/MEncoder. In Fedora, if you'd like to attempt to obtain the appropriate libraries (as root)...


yum install xvidcore*
yum install lame*

Depending on whether or not these packages are already installed, and if you have the appropriate repositories set up properly (see Livna) you'll get various messages indicating yum's success. If the packages are not found, or not available from your repositories - you'll get "nothing to do."

Now, compile and install MPlayer/MEncoder as documented from the README and Installation instructions. While the documentation doesn't really make it obvious that you are building MEncoder, the default make instruction automatically builds MEncoder along with MPlayer at the same time. Note that if you already have a previous version of MPlayer/MEncoder in your PATH environment variable, you'll want to make sure that you're running the version of MPlayer you just compiled.

Remember, these are just settings I use that work well for me. Feel free to tweak them to your liking.

Leave a comment