Log in

View Full Version : Color Space Conversion for HDTV to xvid/divx


wbo
8th March 2005, 20:08
I am not sure whether I should post this in the HDTV forum or the xvid forum, so please forgive me if I am posting this in the wrong place :)

I have searched the forums, but I am having trouble finding a clear answer. What is the proper way to encode HDTV transport streams to xvid/divx using avisynth taking into account any differences in color space?

I have an HDTV transport stream that appears to be a bit too dark when encoded using xvid, and I think the problem may be due to the fact that xvid/divx use a different color space than the HDTV stream.

From what I have been able to figure out, some HDTV streams use the BT709 color space and xvid/divx use the BT601 color space. I have seen several posts that recommend using the BT709toBT601 filter in the avisynth script which makes sense.

I have also seen people recommend using the ColorMatrix filter which does about the same thing and clamps the luma to the TV scale. But should I use the PC luma scale (0-255) or the TV luma scale (16-235) when encoding using xvid/divx?

Wilbert
8th March 2005, 22:49
But should I use the PC luma scale (0-255) or the TV luma scale (16-235) when encoding using xvid/divx?
If you are talking about dvd2avi/dgindex, that setting doesn't do anything when importing the d2v in AviSynth.

wbo
9th March 2005, 02:35
Originally posted by Wilbert
If you are talking about dvd2avi/dgindex, that setting doesn't do anything when importing the d2v in AviSynth. I am referring to the built in AviSynth filters ColorYUV(TV->PC) and ColorYUV(PC->TV) When encoding to MPEG4 xvid/divx should the luma be in levels be restricted or use the full PC range of 0-255?

Wilbert
9th March 2005, 11:25
Luma should be [16,235].

temporance
9th March 2005, 14:10
The problem could be that YUV2RGB conversions done by xvid/divx are designed for the NTSC colorspace. Videocard overlay conversions are also intended for NTSC.

HDTV colorspaces are subtlely different and need a modified matrix to convert to RGB. (Infact PAL colorspace is also not the same as NTSC!)

Wilbert
9th March 2005, 15:42
HDTV colorspaces are subtlely different and need a modified matrix to convert to RGB.
Sometimes. Just as when comparing dvd streams they can be different. I assume you know how to check that (with gspot/dgdecode).

(Infact PAL colorspace is also not the same as NTSC!)
That's only the case for analog stuff.

wbo
9th March 2005, 18:43
Originally posted by temporance
The problem could be that YUV2RGB conversions done by xvid/divx are designed for the NTSC colorspace. Videocard overlay conversions are also intended for NTSC.
So if the HDTV stream is in the BT709 color space I should use BT709toBT601() followed by ColorYUV(PC->TV) to convert the color space to BT601 with the TV luma scale of (16-235).

For streams that are already in the BT601 color space I just need to use ColorYUV(PC->TV) before encoding with xvid. Is that correct?

Wilbert
10th March 2005, 00:12
So if the HDTV stream is in the BT709 color space I should use BT709toBT601() followed by ColorYUV(PC->TV) to convert the color space to BT601 with the TV luma scale of (16-235).

For streams that are already in the BT601 color space I just need to use ColorYUV(PC->TV) before encoding with xvid. Is that correct?
Yes. But are you sure your source is [0,255]?