[MEncoder-users] Any experts? MEncoder places chroma in wrong field...

B.P. pishposh at phreaker.net
Fri Dec 14 11:44:32 CET 2007

I've been sifting through MEncoder's manual for days without finding
a solution to this problem.  I sincerely hope somebody else can spot
what I'm doing wrong.

I'm using MEncoder to transform a series of PNGs into high quality
interlaced MPEG-2 for an NTSC DVD.  Most of the images are photographic
and look perfect regardless of the encoder settings I've tried.

But when it comes to sharp elements like thin colored lines on black
backgrounds, I've had terrible luck producing acceptable encodings.
In every frame of the video, MEncoder places the chroma for *some*
(but not all) of those lines in the wrong interlaced field, resulting
in some of them appearing completely monochrome!  What makes this more
perplexing is that the effect doesn't appear in software players like
MPC or VLC, even when they're configured not to average both fields
together during playback.  It only appears on hardware DVD players and
TVs -- and yes, I've tried several.

Here's a demonstration.

The source test pattern (704x480):

The encoder settings ("imglist.txt" contains the source PNG's filename
90 times to generate about three seconds of video):
mencoder mf://@imglist.txt -mf fps=29.97:w=704:h=480:type=png -ovc
lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=704:480 -lavcopts
-ofps 30000/1001 -o output.mpg

The result when viewed/capped in VLC or MPC:

Some color saturation has been lost on the thinnest lines because of
the 4:2:0, but there's otherwise nothing wrong with it.

The result when played by a hardware DVD player on a television:

And there's where things get ugly.  That's a composite of two digital
camera snapshots of my television.  On the left, the DVD player is
paused so that only one field is showing.  On the right (and mirrored
for convenience), the DVD player is in motion so that both fields are
simultaneously visible.  Notice that on the right, several of the
yellow lines are completely colorless, and that in the paused version
(left), the cause is revealed: their chroma is in the wrong field (the
field where those lines don't exist)!

After lots of experimentation, I discovered the apparent solution to
this mystery - changing "-vf scale=704:480" to "-vf scale=704:480:1:0".
That completely resolved the problem for ordinary DVD player viewing.
But it caused the issue to begin occurring with software playback (in
VLC and MPC)!  http://img266.imageshack.us/img266/2950/vlccap2av8.png

While further researching the issue, I found "ilpack" in the manual:

   "ilpack[=mode]   When interlaced video is stored in YUV 4:2:0
   formats, chroma interlacing does not line up properly due to
   vertical downsampling of the chroma channels. This filter packs
   the planar 4:2:0 data into YUY2 (4:2:2) format with the chroma
   lines in their proper locations, so that in any given scanline,
-> the luma and chroma data both come from the same field."

This seemed to be a literal description of my problem.  So I gave it a
try (with "-vf ilpack,scale=704:480").  While the result caused all
lines to appear in color for both hardware+TV and software viewing,
the color saturation and resolution took an unsatisfactorily nosedive
as a whole (noticeable in both hardware+TV and software playback).  An
example with and without ilpack (both capped in VLC):

Anyway, here is yet another test pattern illustrating the differences
between scale=704:480, scale=704:480:1:0, and ilpack,scale=704:480.
(The loss of color resolution caused by ilpack is especially visible
in the bright reds, blues, and magentas seen in this pattern.)

So.  I'm basically in a situation where I can produce high quality MPEG
encodings of PNGs -- 4:2:0 limitations aside, except that the results
are only compatible with either a TV+DVD player or software playback.

Surely this isn't the way it has to stay.  Any ideas how to fix this?

P.S.  I'll eventually be using the MEncoder command line seen above to
convert images spewed by "ffmpeg -i input.mpg -f image2 foo_%05d.bmp"
back to NTSC MPEG (after processing them).  Am I doing the right thing
by saying "-mf fps=29.97"?  Should I be more precise, like with
"fps=29.969523809", or even "fps=30000/1001"?  Any other recommendations
for my command line as a whole?

Thanks, everyone.

More information about the MEncoder-users mailing list