Will I Get Distorted/Green-Purple Colors When Trying to Play This? [SOLVED]

Please post here for issues related to UHD discs
Post Reply
Apollo11
Posts: 45
Joined: Fri Apr 28, 2023 1:54 pm

Will I Get Distorted/Green-Purple Colors When Trying to Play This? [SOLVED]

Post by Apollo11 » Thu Jun 01, 2023 3:37 pm

I’m wondering whether ripping the 4K version of “No Time To Die” shown below will result in a green-purple tint due to some format problems?:
https://drive.google.com/file/d/1bBS84v ... p=drivesdk

Or will there be no issues since it also uses HDR10?

EDIT: It plays fine on VLC as evidenced by this screenshot:
https://drive.google.com/file/d/1rY02LS ... sp=sharing
PC:
- Desktop: i7-9700K with RTX 2080 8GB w/ Windows 10 Home 64-bit.

- Laptop 1: i7-12700H with RTX 3060 w/ Debian 12 Bookworm + GNOME.

- Laptop 2: i5-7300HQ with GTX 1050 4GB w/ Windows 10 Home 64-bit.

Blu-Ray drive: Pioneer BDR-UD04 v1.14 Firmware.

DJRumpy
Posts: 190
Joined: Thu Aug 18, 2011 9:21 pm

Re: Will I Get Distorted/Green-Purple Colors When Trying to Play This?

Post by DJRumpy » Fri Jun 02, 2023 11:35 pm

Without knowing the specifics of your setup, this is a little difficult to answer.

It requires info on both the source/player/server, and the output display/endpoint, as well as any intervening hardware you may have in between the player/server and the display (like a home theater tuner for example). Everything in the chain must either support HDR, or be able to pass the stream on untouched assuming the next hop knows what to do with it and whether or not that next link supports HDR.

A good example is Plex Media Server. It supports HDR but only provides that support to paying customers. I forget what they call it. Plex Pass or something. In any case, if you try to serve up an HDR and you do not pay for the monthly subscription, Plex which knows what HDR is, but will instead just send the stream on as-is, without converting, and leaves it up to your display, or player to convert or screw up.

That's why the question is a little complicated to answer.

For VLC, it is most likely converting the HDR 10 bit color to standard 8 bit SDR color so it looks 'ok' when viewing it. Note that this is just a guess as we don't know what video hardware you have. I assume this is probably a PC and some PC's do provide hardware decoding for HDR, but it's more likely yours doesn't, and VLC is doing a live conversion to SDR. As a result of this conversion, you may notice a higher than normal CPU load as the conversion can be CPU intensive without dedicated hardware support.

All current 4K players that you buy in the store support basic HDR 10. Support for HDR 10+ or Dolby Vision is not as widespread so you would have to check the specifications. As all of those player support basic HDR 10, you can view HDR disc using the basic HDR, even for Dolby Vision discs. You just don't get the 'fancy' frame by frame color/brightness/contrast adjustments that Dolby Vision provides. Instead it just passes along the color mapping and max brightness, and other parameters that your player can then use to output a basic HDR stream.

When you rip an HDR disk, whether it's Dolby Vision, HDR 10, or HDR10+, the rip will retain that color profile and bit depth, and any players or displays that do not support it will see distorted color, brightness, and contrast values as a result. This means you will see the 'green' output for Dolby Vision on a setup that doesn't support it, or cannot convert it.

You CAN convert an HDR video to SDR using the open source FFMPEG binary. It supports most operating systems and is free for use.You can even convert a 4K video to SDR while retaining the 4K resolution if that's what you are looking for.

I use a simple script on my Mac for this as I keep two copies of a movie (a 4K HDR and an SDR 1080P version). You could do something similar with Windows without too much work. This command will do the color mapping to allow you to convert an HDR10 movie to SDR 8 Bit color. It doesn't do so well with Dolby Vision though. If you're curious as to how, read on.

WARNING: A LOT OF CONFUSING MATH BELOW THAT MAY NOT INTEREST YOU AT ALL. Proceed at your own risk.

So for this sample, I was converting a movie from 4K to 1080P and from HDR to SDR. The source = and target= bits just make it easy to reuse the same command as they store those paths in variables. You can just put the explicit path in your command itself in place of $source and $target if that's easier.

source='/Users/Username/Movies/_Rips/SomeMovieFolder/Some4KMovie.mkv'
target='/Users/Username/Movies/Movie.sdr.1080p.mkv'
ffmpeg -i "$source" -ss 00:14:00 -t 00:01:00 -map 0 -c:a copy -vf scale=1920:1080,zscale=t=linear:npl=57,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p,crop=1920:802:0:139 -c:v hevc_videotoolbox -q:v 65 $target

The above would start encoding the clip at 14 minutes (due to the -ss 00:14:00 - t 00:01:00), and grab exactly 1 minute of video to encode for your test. Remove "-ss 00:14:00 - t 00:01:00" from your command when you are ready to do your final encode.

A few notes: I add the simple trim command (the -SS you see above) in the command to do an output sample just to make sure I've got the crop correct and the output looks good. I remove the "-ss 00:14:00 -t 00:01:00" from the final command so that I ge the full movie. It will run a few minutes without seeing to do anything at first. It's mapping the color, so be patient.

If your video has letterboxing, be sure you set the crop. If it does not have any letterboxing, you need to remove the ,crop=1920:802:0:139 portion of the command including the leading comma.

If you do not own an M1 or M2 Mac, remove the -c:v havoc_videotoolbox piece of the command as it won't be supported on Windows as that is specific to the Mac hardware encoding. If you did not download a binary that has the NEON extensions compiled into FFMPEG, your will need to remove the -c:v havoc_videotoolbox in that case as well. If you have downloaded a precompiled FFMPEG binary that includes the NEON extensions and you have a Mac M1 or M2, you can leave that portion of the command in to enable the hardware encoding. They will give you a huge increase in speed (in some cases well over 100 frames per second). You're mileage may vary :)

Also note that crop=1920:802:0:139 is for a specific movie resolution (1080P) with a specific aspect ratio (2.39). Yours will differ based on its aspect ratio and resolution. 4K movies = 3840x2160 and 1080P are 1920x1080 for resolutions. An easy way to cheat and see the crop is to download the free software Handbrake and drag/drop your MKV onto it. It will show the values being cropped in the "Dimensions" tab. If you aren't interested in how all of that math works for the cropping, just use Handbrake and skip most of the below info.

Now a bunch of math that you probably wish. you hadn't seen, but is necessary if you want to crop, and scale your movie using the FFMPEG command line and understand the math. If you are NOT scaling your video to 1080, remove the "scale=1920:1080," from the final command in the example above. That part of the command will rescale whatever your input video is, to Width and Height specified (1920 W and 1080 H in the example above). If you aren't scaling, remove it.

So, if you are not scaling, and not cropping, and you are doing your final encode on a non Mac your command line might look like this to just convert from HDR to SDR:

ffmpeg -i "$source" -map 0 -c:a copy -vf zscale=t=linear:npl=57,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -q:v 65 $target

What the Crop Values Mean
1920:802:0:139 ( this means Out Width, Out Height, Horizontal Crop (left/right pillar boxing), Vertical Crop (letterboxing crop)

If we have a video with an aspect ratio of 2.39, this means it no pillar boxing on the left and right sides of the video (no black borders on on the horizontal left and right sides), and some pixels we have to remove from the top and bottom Vertical letterboxing.

1920 (with):802 (height):0 (L/R crop):139 (Top/Bttm crop)

Our sample output video is 1920 pixels wide, 802 pixels tall. The third value of "0" is the left/right crop (the amount to remove from the left and right side of the video and this would normally be = 0 ). The last value "139" is the vertical crop and means that it will remove 139 pixels from the top of the video AND 139 pixels from the bottom of the video (1080 height - 139 top minus 139 bottom = 802 or our output video height), totaling 278 total pixels cropped (139 x 2 = 278) from the top and bottom of the video. You may have figured out that the amount we removed in letterboxing PLUS the remaining 802 pixel height should equal our full frame output height ( 139 + 802 + 139 = 1080) for the vertical height.

IMPORTANT: Your cropped values should always total to an even number. 802, or 804, or 800, not 801, 803, 805. The encoder can choke on even values. I usually round to the nearest even number, so 801.3 would round to 802 while 800.5 would round to 800.

This sample command above removes the letterboxing on a 1080P movie that has a 2.39 aspect ratio. If you movie has no letterboxing, you do not need the crop and you would remove the ",crop=1920:802:0:139" from your command.

If you want to understand the math:

To calculate any video's aspect ratio, Simply divide the full video width (example 1920) by the aspect ratio to get the actual output video size, minus any letterboxing. So if our movie has a 1.78 aspect, we would divide 1920 / 1.78 and get approximately 1920 x 1080 (an aspect of 1.78 has no letterboxing so the result is a full vertical height of 1080). If your movie was a 2.20 aspect you would divide 1920 / 2.20 and get 872 pixel height output video. That means you just figure out the difference between the cropped output video size and the full 1080P vertical height to determine the actual amount to crop. 1080 - 872 = 208. That is the TOTAL amount to crop, so divided equally from both the top and the bottom (divide by 2), you get 104 pixels that needs to be cropped from the top and also 104 pixels from the bottom.

The same math also works if you know the width and height of your video, but not the aspect ratio. So if your movie is 1920 x 804, you can simply divide the width (1920) by the height (804) to get the aspect ratio ( 1920 / 804 = 2.39 rounded or an aspect of 2.39:1.

- Divide Width by Video Height (minus letterboxing) to get Aspect Ratio
- Or Divide Width by Aspect Ratio to get Vertical Height (minus letterboxing)

Once you know those basic rules you can figure out most video aspects, cropping, ratios, etc.

If you remove the top and bottom letterbox and our video was a 2.20 aspect ratio, we would be removing 104 pixels from the top and 104 from the bottom for 208 pixels total. 1080 total height - 208 top&bottom = 872 ( 872 is the video content area )

Same for 4K video. Output video width is 3840, and your aspect ratio is 2.35 then your output video width is 3840 / 2.35 = 1634 or better said. 3840 width x 1634 height. Since a full frame 4K movie is 3840 x 2160, you would then know how much is letterboxing by subtracting your video 'content' area from the full frame letterboxed vertical height (2160). To get the letterboxed area and then divide by two for top and bottom values (2160 - 1634 = 526 letterboxed area. 526 / 2 = 263 cropped from both Top and 263 cropped from the bottom.

You can reverse this math if you have a cropped video and want to know its aspect assuming the pixel ratio is 1:1. Let's say you have a DVD and the cropped output video is 720 x 304, your aspect ratio would be 720 / 304 = 2.40.

It gets more complicated with DVD's and anamorphic video where they squeeze a resolution into a lower resolution and then expand it to match the display aspect ratio. A topic for another day ;) It's often easier to just google the video title for the aspect ratio and go from there by dividing the video width by the aspect ratio to get the output video height or if your disc lists the aspect ratio, divide the full width by the aspect to get the cropped output video height.

DJRumpy
Posts: 190
Joined: Thu Aug 18, 2011 9:21 pm

Re: Will I Get Distorted/Green-Purple Colors When Trying to Play This? [SOLVED]

Post by DJRumpy » Sat Jun 03, 2023 12:01 am

You can download precompiled FFMPEG binaries here:

https://ffmpeg.org/download.html

For Apple silicon to enable hardware encoding: http://www.osxexperts.net

Apollo11
Posts: 45
Joined: Fri Apr 28, 2023 1:54 pm

Re: Will I Get Distorted/Green-Purple Colors When Trying to Play This? [SOLVED]

Post by Apollo11 » Sat Jun 03, 2023 9:01 am

DJRumpy wrote:
Sat Jun 03, 2023 12:01 am
You can download precompiled FFMPEG binaries here:

https://ffmpeg.org/download.html

For Apple silicon to enable hardware encoding: http://www.osxexperts.net
Thanks for all the tips! Until I encounter any issues on Plex or VLC regarding this area I'll keep doing what I'm doing now.
PC:
- Desktop: i7-9700K with RTX 2080 8GB w/ Windows 10 Home 64-bit.

- Laptop 1: i7-12700H with RTX 3060 w/ Debian 12 Bookworm + GNOME.

- Laptop 2: i5-7300HQ with GTX 1050 4GB w/ Windows 10 Home 64-bit.

Blu-Ray drive: Pioneer BDR-UD04 v1.14 Firmware.

Post Reply