[MPlayer-users] Scaling and expanding when encoding tv

Jack lt at speakeasy.net
Sun Dec 12 08:28:17 CET 2004

Barton Bosch wrote:

> Here's a noob question that I was surprised not to find a clear answer 
> to in the archives:
> What is the best way to crop the bands and noise from the edges of the 
> frame when capturing NTSC tv from a tuner card and encoding it to mpeg4?

That depends on what you intend to do with the resulting file.

> I gather that it is best to keep the w and h dimensions divisible by 
> 16 and also in a 4:3 ratio.

Yes, especially f you're going to distribute the file to people who 
might play it back with brain-dead players.  However, it's not 
necessary.  See below.

> Which is more important if they are mutually exclusive?
Usually, multiples of 16.  Some video players can't even properly play 
back movies without multiples of sixteen.  Mplayer doesn't have any 
problem with it, but you're still wasting bits.  Not going with 
multiples of 16 wastes bits.

As for the aspect ratio, encoding with "-force-avi-aspect 4/3" will make 
a file that most odml-aware players will scale properly on playback, so 
you don't need to worry too much about making your pixels square.

> This command removes the unwanted areas from all channels but it 
> results in a file with a 1.29:1 aspect ratio, with an x dimension that 
> is not a multiple of 16:
> mplayer tv:// -tv 
> driver=v4l2:device=/dev/video0:chanlist=us-bcast:channel=10:normid=1:width=640:height=480:fps=25 
> -vf crop=618:480:12:0 -vo x11

What's up with 25fps?  This is NTSC, right?

> What is the optimal way to capture and encode NTSC tv? 

That depends on your goals.  If you just want to encode a file that 
you're going to watch once and then kill, that'll look nice in mplayer,  
encode with those options, plus -force-avi-aspect 4/3.  In summary, this.
mencoder tv:// -tv 
-vf crop=618:480:12:0 -force-avi-aspect 4/3 -oac mp3lame -ovc lavc 
-lavcopts vqscale=2 -o quickanddirty.avi

If you're aiming for the highest quality video, playable on a wide 
variety of players, encode first to huffyuv with your options above.  
Then re-encode the resulting file to mpeg4 with your favorite slow, high 
quality options (as if you were ripping a DVD or something), scaling to 
a multiple of 16, and don't forget to add the aspect option.  In 
summary, these.
Step 1:
mencoder tv:// -tv 
-vf crop=618:480:12:0 -force-avi-aspect 4/3 -oac mp3lame -ovc lavc 
-lavcopts vstrict=-1:vcodec=huffyuv -o reallyhugefile.avi
Step 2:
mencoder reallyhugefile.avi -vf scale=608:480 -oac copy -ovc lavc 
-lavcopts trell:v4mv:mbd=2:vqscale=2 -force-avi-aspect 4/3 -o nicefile.avi

If you're looking for something middle-of-the-road, add a scale option 
at the end of the filter chain to scale it down to a multiple of 16, and 
rip straight to mpeg4.  If your machine's too slow for that, crop 
instead of scaling to get a multiple of 16. Somethin like this:
mencoder tv:// -tv 
-vf crop=618:480:12:0,scale=608:480  -force-avi-aspect 4/3 -oac mp3lame 
-ovc lavc -lavcopts vqscale=2 -o prettygood.avi

It's best not to scale the height, only the width, when dealing with TV 
capture, but sometimes it's unavoidable.  Don't forget to add a -endpos 
option, so that mencoder knows when to, um, stop.

> Does the order of filters in the chain matter?

Yes.  Yes it does.  They get applied in the order you type them.  Crop 
before you scale, use common sense.

Making sure that the audio gets captured properly can be a bit tricky, 
and really depends upon your particular setup.  Unless your tv card has 
built-in sound capture (and you have compiled support for it into your 
kernel), you'll have to play with the mixer and figure out what input on 
your sound card the tuner card is plugged into and whatnot, and specify 
it properly in your -tv options (see the man pages on -tv adevice).

Also, some (cheap, crappy) capture cards (such as mine) don't 
deinterlace properly, and you have to use -vf phase to fix it.  If you 
need to, do this BEFORE any scaling.


More information about the MPlayer-users mailing list