• AnyStream is having some DRM issues currently, Netflix is not available in HD for the time being.
    Situations like this will always happen with AnyStream: streaming providers are continuously improving their countermeasures while we try to catch up, it's an ongoing cat-and-mouse game. Please be patient and don't flood our support or forum with requests, we are working on it 24/7 to get it resolved. Thank you.

AnyDVD UHD (4K-HDR)

Hi,

a nice ffmpeg-suggestion to convert 10bit UHD HDR to SDR with HDR-like colours can be found at https://stevens.li/guides/video/converting-hdr-to-sdr-with-ffmpeg/

I've worked out an example for the UHD disc Oblivion. In that example the 3840 * 2160 HEVC HDR source is converted to 1920 * 1080 x264 SDR:

ffmpeg -i oblivion.m2ts -map 0:v:0 -map 0:a:4 -map 0:a:0 -aspect 1920:816 -r 23.976 -vf crop=3840:1632:0:264,scale=1920:816,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx264 -preset fast -profile:v high -crf 18 -ac 2 -c:a aac -b:a 192k -metadata:s:a:0 language=ger -metadata:s:a:1 language=eng -y oblivion-1080p-sdr.mp4

What does this command do?
  • it makes use of the video track (-map 0:v:0) and the german and english audio tracks (-map 0:a:4 -map 0:a:0)
  • it crops the blackbars (crop=3840:1632:0:264)
  • it scales the video down to 1080p (scale=1920:816 -> blackbars taken away, therefore 816 instead of 1080)
  • the colour magic (HDR looking colours in an SDR video) is done by the string "zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p" in the vf-option.
  • the rest is standard: x264 with preset fast, nearly transparent quality by -crf 18, audio conversion and language -tagging
From my point of view it's harder to perform an x265 conversion keeping the HDR properties. Background: To do so, you cannot simply take the ffmpeg Zeranoe builds as they are 8 bit.
That's why you have to build your own ffmpeg 10 bit version which is much more challenging.
I have a hdr lut in abobe premiere but want to test further. I have bluray and hdr material to match the RGB parade and LUMA so the conversion will be accurate for the 4k to 4k h264 to paly on older tvs or whatever. Just pressed for time but I will release my work soon
 
thanks so far. so far it does appear to work. i need to finish converting a few of these to verify the results,
but so far this is the best and only solution to downgrade hdr to sdr.
i'm now working on getting the quality up while keeping the total bits used to a minimum.
need to fit (4) 1hr clips onto 1 bd25.

ffmpeg -i AC_S01E01.mkv -map 0:1 -c copy -map 0:v:0 -aspect 1920:1080 -r 23.976 -vf crop=3840:1920:0:0,scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx264 -preset veryslow -profile:v high -level 4.1 -crf 12 -y output_AC_S01E01h264.mkv
 
thanks so far. so far it does appear to work. i need to finish converting a few of these to verify the results,
but so far this is the best and only solution to downgrade hdr to sdr.
i'm now working on getting the quality up while keeping the total bits used to a minimum.
need to fit (4) 1hr clips onto 1 bd25.

ffmpeg -i AC_S01E01.mkv -map 0:1 -c copy -map 0:v:0 -aspect 1920:1080 -r 23.976 -vf crop=3840:1920:0:0,scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx264 -preset veryslow -profile:v high -level 4.1 -crf 12 -y output_AC_S01E01h264.mkv

Hi,

you don't write how many audio tracks you have in the file AC_S01E01.mkv. In my reply I assume it's one audio track only.

If you want to fit 4 videos of 1 hour on one BD25, then each should get a size of 6 GB. This would lead to a bitrate of 14.3 Mbits.

As you must consider the size of the audio track and some overhead for the container, I would suggest to try a bitrate of 13M for the video part of each video. Maybe better 12M to be on the safe side.

If you have a given bitrate then the best will be to do the classic 2 pass conversion with ffmepg. The 1st pass to write the log file and the second pass to write the video.

You can do that with ffmpeg as follows. Please note that I've adjusted your encoding string a bit.

1st pass
Code:
ffmpeg -i AC_S01E01.mkv -map 0:v:0 -map 0:a:0 -aspect 1920:1080 -r 23.976 -vf scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx264 -preset fast -profile:v high -level 4.1 -b:v 12M -ac 2 -c:a aac -b:a 192k -pass 1 -passlogfile AC_S01E01 -f matroska -y NUL

2nd pass
Code:
ffmpeg -i AC_S01E01.mkv -map 0:v:0 -map 0:a:0 -aspect 1920:1080 -r 23.976 -vf scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx264 -preset fast -profile:v high -level 4.1 -b:v 12M -ac 2 -c:a aac -b:a 192k -pass 2 -passlogfile AC_S01E01 -y output_AC_S01E01h264.mkv

Hope that helps.
 
thanks, so you recommend a 2nd pass.

i am currently getting 15.5mbit overall bit rates.
i put 3 on disk1, 4 on disk2, 3 on disk3, totaling 10 episodes.
audio is 640k ac5.1
7 are done so far working on last 3.

i will try your approach on episode 1 only and compare to my output so far before i burn disks.
thanks for your help. if you didn't come up with this, i would have had to accept the 6mbitrate
from netflix 1080p version. no one has a mapping of HDR to SDR except this.
others say they are working on it, but they are lost.
i can watch the original 4k HDR letting the oppo 203 downconvert, and it does a really good job,
but i want these on disk and off my drive.

thanks again.
 
ok ran 2 pass version it seems a tad better but ...
i do have with all of these though.

after analyzing more, it seems that there is too much red, and it seems to be bleeding over
into the blue sky and is too strong throughout.
is there a way to tone the red down a bit and reduce the artifacts ffmpeg is producing in general.
 
audio is 640k ac5.1

Hm, it's not clear to me, whether you want to copy or convert the audio track. In my reply I'll assume now that you want to copy it.

reduce the artifacts ffmpeg is producing in general

You would like to improve the overall quality of the encodes? Then I'd suggest to use x265 (HEVC) instead of x264 (AVC) at the same bitrate. This will improve quality significantly.

A 2-pass encoding would then look as follows.

First pass
ffmpeg -i AC_S01E01.mkv -map 0:v:0 -map 0:a:0 -aspect 1920:1080 -r 23.976 -vf scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx265 -preset fast -b:v 12M -an -pass 1 -f matroska -y NUL

Second pass
ffmpeg -i AC_S01E01.mkv -map 0:v:0 -map 0:a:0 -aspect 1920:1080 -r 23.976 -vf scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx265 -preset fast -b:v 12M -c:a copy -pass 2 -f matroska -y output_AC_S01E01h265.mkv

is there a way to tone the red down a bit

Converting HDR to SDR is challenging because colours not existing in the SDR colorspace must be mapped to it. Of course ffmpeg has some switches to reduce a specific colour. The question is whether this will be good for all material.

You can try e.g. the "curves" filter, but it's hard for me to guess what will happen without a look at the videos you are converting.

To apply that filter you can extend the vf statement. Append curves=red="0/0 0.5/0.4 1/0.8" and it will reduce red a bit:

Code:
-vf scale=1920:1080,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p,curves=red="0/0 0.5/0.4 1/0.8"
 
Last edited:
I'm playing with Adobe premiere 8.1.1.1 and using Intel's GPU acceleration to encode min for min HDR to sdr 4k tests. The final does not have HDR but rec709 and my tests are exactly what you get from madvrs 120 nit pixels shader math. Madvr does wonderful HDR conversion. Love Intel's GPU encoding. A 4 k rip that's 1 hr takes 1 hr to encode 40mbit lol. H265 real HDR takes me 6-8 hrs on my Intel 8700k using straxrip with 10bit UHD HDR output.
 
I'm playing with Adobe premiere 8.1.1.1 and using Intel's GPU acceleration to encode min for min HDR to sdr 4k tests. The final does not have HDR but rec709 and my tests are exactly what you get from madvrs 120 nit pixels shader math. Madvr does wonderful HDR conversion. Love Intel's GPU encoding. A 4 k rip that's 1 hr takes 1 hr to encode 40mbit lol. H265 real HDR takes me 6-8 hrs on my Intel 8700k using straxrip with 10bit UHD HDR output.

Hi,

last year I've tried around a while with Intel qsv and Nvidia nvenc. I've then choosen nvenc because it was faster and more reliable.

But there's one thing you can read everywhere and you should keep in mind when it comes to GPU acceleration: Quality will suffer a lot or you must accept a significant increase in file size.
 
Hi,

last year I've tried around a while with Intel qsv and Nvidia nvenc. I've then choosen nvenc because it was faster and more reliable.

But there's one thing you can read everywhere and you should keep in mind when it comes to GPU acceleration: Quality will suffer a lot or you must accept a significant increase in file size.
True I'm YouTube creator so this GPU add-on is a dream for kabylake GPUs. My old h264 rips were done at 18mbit with untouched audio and they looked great. HDR to sdr is a biych. Even with rgb and luma scopes I still can get a perfect match but my test lut is really close. When I get it perfect I'll share it. Until then I'll keep at it. I'm using madvrs output as a reference. The problem lies in the white black level or HDR to sdr. The color shift to from bt2020 to rec709.
 
Hi,

I've just found an interesting suggestion of Google to convert HDR to SDR using a LUT:
https://developers.google.com/media/vp9/hdr-encoding/

Search the page for:
"Converting HDR to SDR"

They do it for VP9, but it can easily be adjusted to AVC/HEVC. To be able to let it run, you must download the LUT file from:
https://storage.googleapis.com/medi...te/vp9/input/hdr/bt2020_to_bt709_example.cube

I've tried it with a UHD HDR demo (see http://4kmedia.org/lg-chess-hdr-demo/ as source). The encoding string for HEVC would look as follows:

Code:
ffmpeg -analyzeduration 10M -probesize 10M -i chess.mp4 -map 0:v:0 -map 0:a:0 -aspect 1920:1080 -color_primaries 1 -color_trc 1 -colorspace 1 -color_range 1 -pix_fmt yuv420p -vf scale=1920:1080:in_color_matrix=bt2020,format=rgb48,lut3d=bt2020_to_bt709_example.cube,scale=1920:1080:out_color_matrix=bt709 -c:v libx265 -preset fast -crf 18 -ac 2 -c:a aac -b:a 128k -y chess-sdr-google.mp4

But to be honest, there's not much difference between the zscale-encodings I've posted before and this one.
 
Cool to know my cube lut will work in straxrip. Almost got my HDR to sdr lut done.
 
The way I do it is load the rip into straxrip. Select ffmpeg PRO RES and ffmpg MOV container in options. Do the encode. Open adobe premiere any version and drag the clip onto the timelime. Add lumiti color and select custom lut in basic color correction settings and add my hdr sdr lut. Its almost exact to the hdr material including the color. This is ONLY for users who cannot play hevc as you simply just use madvr pixel shader math to convert while playback. IF YOU ARE NOT running a system that CANNOT keep up or want to transfer to non uhd players this is the method you use. After applying my special lut the file will look identicle to the madvr playback. Simple export using a good bitrate and it will create the h264 file. Now mux the original atmos or dtshd into an mkv and scrap the shitty audio and your done. Your whole 4k collection can be converted with ease. Another thing is your a power user like me you can covert hdr to sdr in REAL time if you happen to own an intel kaby lake processor and adobe premire 8.1.1.1 You can turn on hardware acceleration support and the cpu will use all cores as well as the gpu side of the cpu and the results are amazing! Here is the link to the LUT for adobe premiere. I don't have time to make a video on this.... The advantage of my method is you can use the fast encoder to take 3/4 of the time off each hdr sdr transfer.

https://drive.google.com/open?id=1dvjFRvtee7CFyu_xn24EEiRmKW4M8sQr
 
here is the screen shots of my transfer to rec709 no banding!

2018.06.23-17.27.png 2018.06.23-17.27_01.png 2018.06.23-17.28.png 2018.06.23-17.28_01.png 2018.06.23-17.28_02.png 2018.06.23-17.29.png
 
heres another test clip to get an idea. Enjoy my work......

2018.06.23-17.40.png 2018.06.23-17.41.png 2018.06.23-17.41_01.png 2018.06.23-17.41_02.png 2018.06.23-17.41_03.png 2018.06.23-17.41_04.png
 
Back
Top