Log in

View Full Version : Totally confused. DVD to X264 color conversion? Levels? RGB?


Logan9778
18th March 2017, 01:50
Hi guys.

I'm getting really confused about if I need to convert to RGB from a YUV DVD rip (MPEG2). Again I'm working on Doctor Who - An Unearthly Child (black and white). I keep seeing in articles they talk about DVD having a 16-235 color range. And of course, RGB is 0-255. Do I need to do any kind of conversion of chroma or luma to get the rip to show colors correctly on an HDTV, like BTB and WTW?

I've looked at Levels(), and ConvertToRGB(), but I'm still confused if I need to use them or not for RGB display (HDTV) with Plex software.

Thanks again for all the help you've given me! Most of the Wiki articles are pretty confusing for a beginner. I've searched and searched forums, but I can't see a definite answer to this.

mariush
18th March 2017, 02:35
When movies are compressed into a particular format, each pixel in the image is converted from RGB (red, green, blue) to a set of values called YCbCr (Luminance and Chrominance). This makes it possible to compress the video better but keep more quality in an amount of bytes.

The formula used to convert from RGB to YCbCr in the case of SD content (MPEG-1 , MPEG-2 DVD etc) is called Rec.601 or bt601 : https://en.wikipedia.org/wiki/Rec._601

When your DVD player decodes the video, it reads video frames from the MPEG-2 files on the DVD and using the Rec.601 formula, it converts the image from YCbCr back to RGB and then sends the image to TV.

Yes, there are also two flavours of this encoding, the one where a RGB image is converted to Limited YCbCr (where ranges are valid between 16 and 235) or Full YCbCr (or PC Levels, where each value ranges from 0 to 255). When the video is decoded, the decoder detects if the video is encoded as Limited YCbCr or Full YCbCr and uses the proper formula to convert to RGB correctly.

With HD content (blurays, HD broadcasts) when files are encoded they still convert each image from RGB to YCbCr but they use a better formula for the conversion called Rec.709 or bt.709 : https://en.wikipedia.org/wiki/Rec._709
Video players typically read from the file that it's a HD file and use the new formula to convert back to RGB correctly. When the information is not in the file, they guess based on width and height ... for example anything wider than 720 pixels or anything higher than 576 pixels (as PAL DVDs are 720x576) is assumed to be a HD file and they use the Rec.709 formula to convert back to RGB and send the image to the monitor. This makes it possible for the video player to detect a 4:3 HD video correctly.

So for example, you'd want to do some color conversions only if you grab a HD source and create a SD version, for example to create a DVD out of something your recorded in HD. If you just resize, then after encoding the software you use may convert to SD using the same Rec.709 formula, but the DVD player will simply assume the formula to use is Rec.601 because that's all that was used for DVDs. Then the colors may look different.

Anyway ... no, you probably don't have to do anything. If you're going to use x264 to convert the MPEG-2 file to mkv (encoded with x264), it may be worth specifying the color matrix in parameters, so that whatever video player you use will apply the correct one (for example the software in your smart tv)

x264 uses the code bt470bg which is a synonim for Rec.601 (same parameters) which is valid for PAL DVDs , and bt470m for the NTSC SD DVDs ... check which one was used with various software players. DGIndex will load a mpg or vob file and when you hit preview, it will tell you the colorimetry used.

x264.exe --preset slower --tune film --crf 18 --colormatrix bt470bg --colorprim bt470gb --transfer bt470bg -o "output.mkv" "input.mpg"

Logan9778
18th March 2017, 03:09
Thanks! And thanks for telling me the reason YUV exists. I would have thought it would have been RGB on a Bluray. I didn't know if I needed to manually convert colors or such to show correctly on a HD monitor. I will try putting these parameters into X264.

Asmodian
18th March 2017, 19:58
Just a small comment that doesn't change mariush's recommendation but BT.709 is not better than BT.601, it is simply different. BT.601 uses the primary colors of old CRT TVs while BT.709 uses the primary colors of newer HDTVs/PC Monitors.

The gamut is actually a little wider with BT.601 but this doesn't really mean anything as far as workflow recommendations. As mariush said, don't convert unless you are resizing HD to SD resolutions or SD to HD resolutions. I use 1024x576 as the maximum SD resolution, e.g. a widescreen PAL DVD resized to square pixels. Because there is no true standard for exactly which resolutions should be converted to RGB using BT.601 or BT.709 always flag the video with --colormatix, --colorprim, and --transfer.

Logan9778
20th March 2017, 07:17
Thanks, Asmodian! I'll keep that in mind.