FastFlix icon indicating copy to clipboard operation
FastFlix copied to clipboard

Why Remove HDR leaves HDR traces in the output file

Open end2endzone opened this issue 2 years ago • 1 comments

Hi. Why does using options Remove HDR, does fully not remove the "HDR Format" flag in the output file?

I am trying to convert an HDR sample file to SDR. However the output file I get is still identified as HDR by Jellyfin or Emby. I think this is because the output file has the HDR Format set to Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible according to MediaInfo.

When I am checking the Remove HDR, my assumptions are that all HDR metadata should be removed. Pixel brightness should be corrected according to a tone mapping rule as if we would be burning-in the HDR metadata to the output pixels. After this process, we end up with a H.264/H.265 stream that is 8 bit or 10 bit and not identified as "HDR" anymore.

I suspect that I might not be using FastFlix as intended. Please feel free to correct me or indicate me what I should be doing to remove the "HDR Format" flag in the output file.

I tried to convert the source file to the following output formats.

  • H.264, 8 bit
  • H.264, 10 bit
  • H.265, 8 bit
  • H.265, 10 bit

All of the above have the output file with the flag HDR format set to Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible.

I am using FastFlix 4.10.0 and ffmpeg 5.1.2 :

ffmpeg version 5.1.2-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100

Here is the command line I used: "D:\Apps\ffmpeg\ffmpeg-5.1.2-full_build\bin\ffmpeg.EXE" -y -i "E:\Recordings\HDR to SDR tests\source.mkv" -max_muxing_queue_size 1024 -filter_complex "[0:0]scale=1920:-8:flags=lanczos,format=p010,hwupload,tonemap_opencl=tonemap=hable:desat=0:r=tv:p=bt709:t=bt709:m=bt709:format=nv12,hwdownload,format=nv12[v]" -map "[v]" -c:v libx264 -pix_fmt yuv420p -init_hw_device opencl=ocl -filter_hw_device ocl -crf:v 20 -preset:v medium -map_metadata -1 -map_chapters 0 -map 0:1 -metadata:s:1 title="" -metadata:s:1 handler="" -c:1 copy -default_mode infer_no_subs "E:\Recordings\HDR to SDR tests\source - fastflix.H264.1080p.8bit-hable.mkv"

Source file:

General
Complete name                            : E:\Recordings\HDR to SDR tests\source.mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 166 MiB
Duration                                 : 47 s 797 ms
Overall bit rate                         : 29.1 Mb/s
Encoded date                             : UTC 2022-10-16 21:40:47
Writing application                      : mkvmerge v63.0.0 ('Everything') 64-bit
Writing library                          : libebml v1.4.2 + libmatroska v1.6.4

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main 10@L5@High
HDR format                               : Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible / SMPTE ST 2094 App 4, Version 1, HDR10+ Profile B compatible
Codec ID                                 : V_MPEGH/ISO/HEVC
Duration                                 : 47 s 797 ms
Bit rate                                 : 28.7 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 024 pixels
Display aspect ratio                     : 1.897
Frame rate mode                          : Constant
Frame rate                               : 23.976 (23976/1000) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0 (Type 2)
Bit depth                                : 10 bits
Bits/(Pixel*Frame)                       : 0.154
Stream size                              : 163 MiB (99%)
Default                                  : Yes
Forced                                   : No
Color range                              : Limited
Color primaries                          : BT.2020
Transfer characteristics                 : PQ
Matrix coefficients                      : BT.2020 non-constant
Mastering display color primaries        : Display P3
Mastering display luminance              : min: 0.0050 cd/m2, max: 1000 cd/m2
Maximum Content Light Level              : 897 cd/m2
Maximum Frame-Average Light Level        : 497 cd/m2

Output file (H.264 8bit one) :

General
Complete name                            : E:\Recordings\HDR to SDR tests\source - fastflix.H264.1080p.8bit-hable.mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 61.2 MiB
Duration                                 : 47 s 763 ms
Overall bit rate                         : 10.7 Mb/s
Writing application                      : Lavf59.27.100
Writing library                          : Lavf59.27.100
ErrorDetectionType                       : Per level 1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
HDR format                               : Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 47 s 756 ms
Bit rate                                 : 10.1 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 016 pixels
Display aspect ratio                     : 1.897
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.217
Stream size                              : 57.7 MiB (94%)
Writing library                          : x264 core 164 r3099 e067ab0
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=24 / lookahead_threads=4 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=20.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Default                                  : Yes
Forced                                   : No
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

end2endzone avatar Oct 16 '22 23:10 end2endzone

Tried it myself, looks like ffmpeg now properly recognize and copy DV side data:

Side data:
      DOVI configuration record: version: 1.0, profile: 7, level: 6, rpu flag: 1, el flag: 1, bl flag: 1, compatibility id: 6

The actual video is converted correctly to a non HDR colorspace. However, keeps the side data. Not sure if it messes it up at all or not.

Need to figure out how to remove just a side data stream, don't see any quick references online for it, so may be "fun" to figure out.

cdgriffith avatar Oct 17 '22 02:10 cdgriffith