AnyDVD UHD (4K-HDR)

Discussion in 'High Definition Software' started by Futuria, Mar 17, 2017.

  1. gereral1

    gereral1 Well-Known Member

    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
     
  2. jetli

    jetli Member

    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
     
  3. fornit

    fornit Member

    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.
     
  4. jetli

    jetli Member

    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.
     
  5. jetli

    jetli Member

    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.
     
  6. fornit

    fornit Member

    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.

    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

    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: Jun 20, 2018
  7. gereral1

    gereral1 Well-Known Member

    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.
     
  8. fornit

    fornit Member

    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.
     
  9. gereral1

    gereral1 Well-Known Member

    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.
     
  10. fornit

    fornit Member

    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.
     
  11. gereral1

    gereral1 Well-Known Member

    Cool to know my cube lut will work in straxrip. Almost got my HDR to sdr lut done.
     
  12. gereral1

    gereral1 Well-Known Member

    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
     
  13. gereral1

    gereral1 Well-Known Member

    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
     
  14. gereral1

    gereral1 Well-Known Member

    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
     
  15. gereral1

    gereral1 Well-Known Member

    and here is the original washed out hdr I used

    2018.06.23-18.08.png