====== HDR (High Dynamic Range / Dolby Vision) ====== HDR10 ist ein Open-Source-Format, das von vielen TV- und Videomonitorherstellern, Spielsystemen und Streaming-Plattformen unterstützt wird. Es nutzt den ''Rec. 2020''-Farbraum, ''10-Bit''-Sampling und ''SMPTE ST 2084 (PQ)''-Übertragungsfunktion sowie statische Metadatenwerte für Elemente wie ''MaxCLL (Maximum Content Light Level)'' und ''MaxFALL (Maximum Frame-Average Light Level)''. ===== HDR in SDR umwandeln ===== * [[https://ericswpark.com/blog/2022/2022-12-14-ffmpeg-convert-hdr-to-sdr/]] * [[https://stackoverflow.com/questions/52132839/ffmpeg-convert-hdr-to-sdr]] * [[https://codecalamity.com/encoding-settings-for-hdr-4k-videos-using-10-bit-x265/]] * [[https://stackoverflow.com/questions/61460247/10bit-hdr-to-10bit-sdr-conversion-with-ffmpeg]] 10-Bit-Filme (HDR) in 8-Bit-Filme (mit x265) umwandeln: > ffmpeg -i hdr-film.mkv -c:v libx265 -preset ultrafast -x265-params lossless=1 -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -an -sn -dn -reset_timestamps 1 -y film_non_hdr.mkv > ffmpeg -i input.mkv -vf 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 -crf 10 -preset fast output.mkv ===== VP9 ===== * [[https://developers.google.com/media/vp9/hdr-encoding?hl=de|Google: VP9 HDR-Codierung]] * [[https://thuannguyen.net/google-vp9-hdr-encoding-with-ffmpeg.html|[Google VP9] HDR Encoding with ffmpeg]] ### HDR-Parameter: -pix_fmt yuv420p10le -color_primaries 9 -color_trc 16 -colorspace 9 -color_range 1 > ffmpeg -probesize 9223372036854M -analyzeduration 9223372036854M -fflags +genpts -i HDR-Film.mkv -pix_fmt yuv420p10le -color_primaries 9 -color_trc 16 -colorspace 9 -color_range 1 -map 0:v -c:v libvpx-vp9 -crf 32 -b:v 0 -vf pad='max(iw\,ih*(16/9)):ow/(16/9):(ow-iw)/2:(oh-ih)/2:black',scale=1920x1080,setdar='16/9' -keyint_min 2-8 -c:a libvorbis -q:a 6 -map 0:a:0 -sn -dn -disposition:a:0 default -metadata title="test 02" -metadata description='Es wird erwartet, dass die Farben hinterher immer noch passen.' -f webm -y test_06.webm ===== AV1 ===== * [[https://aomediacodec.github.io/av1-hdr10plus/]] * [[https://github.com/rigaya/QSVEnc/issues/92]] # --colormatrix bt2020nc --colorprim bt2020 --transfer smpte2084 --master-display G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,500) --max-cll 1000,300 ===== x265 ===== * [[https://codecalamity.com/encoding-uhd-4k-hdr10-videos-with-ffmpeg/]] * [[https://codecalamity.com/encoding-settings-for-hdr-4k-videos-using-10-bit-x265/]] Extract the Mastering Display metadata: > ffprobe -hide_banner -loglevel warning -select_streams v -print_format json -show_frames -read_intervals "%+#1" -show_entries "frame=color_space,color_primaries,color_transfer,side_data_list,pix_fmt" -i GlassBlowingUHD.mp4 { "frames": [ { "pix_fmt": "yuv420p10le", "color_space": "bt2020nc", "color_primaries": "bt2020", "color_transfer": "smpte2084", "side_data_list": [ { "side_data_type": "Mastering display metadata", "red_x": "35400/50000", "red_y": "14600/50000", "green_x": "8500/50000", "green_y": "39850/50000", "blue_x": "6550/50000", "blue_y": "2300/50000", "white_point_x": "15635/50000", "white_point_y": "16450/50000", "min_luminance": "50/10000", "max_luminance": "40000000/10000" }, { "side_data_type": "Content light level metadata", "max_content": 0, "max_average": 0 } ] } ] } G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000, 50) Convert the video > ffmpeg -i GlassBlowingUHD.mp4 -map 0 -c:v libx265 -x265-params hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50):max-cll=0,0 -crf 20 -preset veryfast -pix_fmt yuv420p10le GlassBlowingConverted.mkv ==== Extracting and encoding with HDR10+ metadata ==== Check to make sure your video has HDR10+ information it can read. > ffmpeg -loglevel panic -i input.mkv -c:v copy -vbsf hevc_mp4toannexb -f hevc - | hdr10plus_parser --verify - Parsing HEVC file for dynamic metadata… Dynamic HDR10+ metadata detected. Once you confirmed it exists, extract it to a json file > ffmpeg -i input.mkv -c:v copy -vbsf hevc_mp4toannexb -f hevc - | hdr10plus_parser -o metadata.json - You just need to pass the metadata file via the ''dhdr10-info'' option in the ''x265-params''. And don’t forget to add your audio and subtitle settings! > ffmpeg.exe -i input.mkv -c:v libx265 -pix_fmt yuv420p10le -x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1):max-cll=1016,115:hdr10=1:dhdr10-info=metadata.json" -crf 20 -preset medium "output.mkv" Using custom compiled x265 > ffmpeg -loglevel panic -y -i input.mkv -to 30.0 -f yuv4mpegpipe -strict -1 - | x265 - --y4m --crf=20 --repeat-headers --hdr10 --colorprim=bt2020 --transfer=smpte2084 --colormatrix=bt2020nc --master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)" --max-cll="1016,115" -D 10 --dhdr10-info=metadata.json output.hevc Saving Dolby Vision > ffmpeg -i GlassBlowing.mp4 -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p10le - | x265-10b - --input-depth 10 --output-depth 10 --y4m --preset veryfast --crf 22 --master-display "G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50)" --max-cll "0,0" --colormatrix bt2020nc --colorprim bt2020 --transfer smpte2084 --dolby-vision-rpu glass.rpu --dolby-vision-profile 8.1 --vbv-bufsize 20000 --vbv-maxrate 20000 glass_dv.hevc