Discussion:
[Mjpeg-users] chroma sample alignment
Adam M. Costello
2001-12-09 05:28:03 UTC
Permalink
The YUV4MPEG2 format specified in yuv4mpeg.h is silent on the alignment
of the chroma samples; it simply says 4:2:0. For MPEG-1, the chroma
samples are supposed to be here:

Y Y
C
Y Y

But for MPEG-2 the chroma samples are supposed to be here:

Y Y
C
Y Y

mpeg2enc can output both MPEG-1 and MPEG-2 streams, but neither the
input stream nor the command-line options contain explicit information
about the alignment of the input chroma samples. So it must do one of
two things:

1) It assumes that all yuv4mpeg streams contain chroma samples aligned
for MPEG-2, and it resamples if the output is MPEG-1. Or vice-versa.

or

2) It assumes that the input yuv4mpeg stream contains chroma
samples suitably aligned for the output format. It's the caller's
responsibility to ensure that this is true.

If (2) is true, then it would seem that lav2yuv and yuv2lav ought
to have command-line options for indicating which alignment to
produce/expect, but they don't.

What is the story on chroma alignment? Does mjpegtools follow the
standards? Do most software MPEG implementations? Do most hardware
MPEG implementations?

Thanks,
AMC
Matto Marjanovic
2001-12-10 19:41:03 UTC
Permalink
Post by Adam M. Costello
The YUV4MPEG2 format specified in yuv4mpeg.h is silent on the alignment
of the chroma samples; it simply says 4:2:0.
Correct. I think I am the only developer who both (a) noticed that there
is a choice and (b) is still worried about it. I'm in the midst of writing
sampling/resampling code for some utilities (e.g. ppmtoy4m and conversion
of DV files).

It's actually a complex issue...
Post by Adam M. Costello
For MPEG-1, the chroma
Y Y
C
Y Y
Y Y
C
Y Y
...for example, for MPEG-2 interlaced streams, the subsampling is per field,
and the vertical siting is actually 1/4 line above or below the luma.
Post by Adam M. Costello
2) It assumes that the input yuv4mpeg stream contains chroma
samples suitably aligned for the output format. It's the caller's
responsibility to ensure that this is true.
It's (2) --- because mpeg2enc just takes the chroma as given to it.
Post by Adam M. Costello
If (2) is true, then it would seem that lav2yuv and yuv2lav ought
to have command-line options for indicating which alignment to
produce/expect, but they don't.
I've got some such options in the works for DV files, because DV-NTSC has
to be resampled anyway (from 4:1:1), so I figure one might as well do it
right if one can take the speed hit.
MJPEG captures are another story. I think they are already 4:2:0, but it
is not obvious (to me) what the chroma siting is to begin with, and
resampling might just introduce more noise than it is worth. (I don't
ever use MJPEG, so I have no experience with this.)
Post by Adam M. Costello
What is the story on chroma alignment? Does mjpegtools follow the
standards? Do most software MPEG implementations? Do most hardware
MPEG implementations?
My guesses to the answers are:

a) "http://www.mir.com/DMG/chroma.html"

b) mjpegtools mostly seems oblivious to the arcane points of the standards.

c) Probably not. A lot of (free) video software doesn't even get YCbCr
right. (Quality stuff like Final Cut Pro, on the other hand, probably
does.)

d) Probably yes.


-matt m.
Adam M. Costello
2001-12-10 23:24:02 UTC
Permalink
Post by Matto Marjanovic
It's (2) --- because mpeg2enc just takes the chroma as given to it.
That's good to know, thanks.
Post by Matto Marjanovic
MJPEG captures are another story. I think they are already 4:2:0, but
it is not obvious (to me) what the chroma siting is to begin with
I don't know either. Maybe the card resamples to 4:2:0, or maybe the
card outputs 4:2:2 and the application does the resampling. Either way
resampling is being performed somewhere.

If you want a simple raw capture, I think 4:2:2 is the natural format.
Then, to maintain image quality as much as possible, you'd want to
perform all your filtering (like noise reduction, inverse telecine,
scaling, etc) on 4:2:2 data. Only at the very end, just before MPEG
encoding, should you convert to 4:2:0.

As you say in your web page, 4:2:2 always has co-sited chroma samples,
so I would hope that's what a video card gives you when you ask for
4:2:2.
Post by Matto Marjanovic
I'm in the midst of writing sampling/resampling code for some
utilities (e.g. ppmtoy4m and conversion of DV files).
If you want to get really ambitious, you could extend the yuv4mpeg
format to support 4:2:2 (and maybe even 4:1:1), and extend all the yuv
filters to support this, and extend mpeg2enc to do the conversion to
4:2:0. :)

AMC

Loading...