Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
#1 | Link |
|
Registered User
Join Date: Jan 2007
Posts: 10
|
Preserving HDR metadata when transcoding
With a UHD HDR 4K blu-ray source that's been converted into an mkv, is it possible to transcode with ffmpeg and x265 and retain the HDR metadata? I'm using a compiled version of ffmpeg with the 10 bit version of libx265. With the following command, the output looks very flat.
ffmpeg -i input.mkv -c:v libx265 -preset medium -x265-params crf=21 output.mkv I've also tried adding various x265 parameters but it either has no effect on the output or it seems to transcode it to SDR. Thanks. |
|
|
|
|
|
#3 | Link |
|
Registered User
Join Date: Jan 2018
Posts: 2
|
I've been having problems with this as well. It seems like most of the metadata is carried over to the container yet when trying to play the encoded file on my LG HDR TV it doesn't switch to HDR, the source sample file does and plays fine.
I've need trying all sorts of different combinations but not having much luck. Any ideas what I might be doing wrong? ffmpeg version Code:
ffmpeg version 3.4.1-1~16.04.york0 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609 configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100 Code:
ffmpeg -i "Sample_HDR.mp4" -pix_fmt yuv420p10le -vf scale=out_color_matrix=bt2020:out_h_chr_pos=0:out_v_chr_pos=0,format=yuv420p10 -c:v libx265 -preset medium -x265-params :colorprim=bt2020:transfer=smpte-st-2048:colormatrix=bt2020nc:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(12000000,200)":max-cll=0,0:repeat-headers -c:a copy -max_muxing_queue_size 4096 "Sample_HDR-encode.mkv" Code:
Video ID : 1 Format : HEVC Format/Info : High Efficiency Video Coding Format profile : Main 10@L5.1@High Codec ID : hev1 Codec ID/Info : High Efficiency Video Coding Duration : 54 s 375 ms Bit rate : 44.8 Mb/s Width : 3 840 pixels Height : 2 160 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 24.000 FPS Original frame rate : 23.976 (24000/1001) FPS Color space : YUV Chroma subsampling : 4:2:0 (Type 2) Bit depth : 10 bits Bits/(Pixel*Frame) : 0.225 Stream size : 290 MiB (99%) Writing library : ATEME Titan KFE 3.7.0 (4.7.0.2002) Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 1904-01-01 00:00:00 Color range : Limited Color primaries : BT.2020 Transfer characteristics : SMPTE ST 2084 Matrix coefficients : BT.2020 non-constant Mastering display color primaries : R: x=0.680000 y=0.320000, G: x=0.265000 y=0.690000, B: x=0.150000 y=0.060000, White point: x=0.312700 y=0.329000 Mastering display luminance : min: 0.0200 cd/m2, max: 1200.0000 cd/m2 Code:
Video ID : 1 Format : HEVC Format/Info : High Efficiency Video Coding Format profile : Main 10@L5@Main Codec ID : V_MPEGH/ISO/HEVC Duration : 54 s 375 ms Bit rate : 64.1 Mb/s Width : 3 840 pixels Height : 2 160 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 24.000 FPS Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 10 bits Bits/(Pixel*Frame) : 0.322 Stream size : 416 MiB (98%) Writing library : x265 2.6:[Linux][GCC 5.4.0][64 bit] 10bit Encoding settings : cpuid=1173503 / frame-threads=4 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=3840x2160 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=3 / no-allow-non-conformance / repeat-headers / annexb / no-aud / no-hrd / info / hash=0 / no-temporal-layers / open-gop / min-keyint=24 / keyint=250 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=20 / lookahead-slices=8 / scenecut=40 / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=0 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=2 / limit-refs=3 / no-limit-modes / me=1 / subme=2 / merange=57 / temporal-mvp / weightp / no-weightb / no-analyze-src-pics / deblock=0:0 / sao / no-sao-non-deblock / rd=3 / no-early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / no-b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.00 / psy-rdoq=0.00 / no-rd-refine / analysis-reuse-mode=0 / no-lossless / cbqpoffs=0 / crqpoffs=0 / rc=crf / crf=12.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.30 / aq-mode=1 / aq-strength=1.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=32 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=1 / overscan=0 / videoformat=5 / range=0 / colorprim=9 / transfer=0 / colormatrix=9 / chromaloc=0 / display-window=0 / master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1) / max-cll=1000,400 / min-luma=0 / max-luma=1023 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / no-opt-cu-delta-qp / no-aq-motion / hdr / no-hdr-opt / no-dhdr10-opt / analysis-reuse-level=5 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-mv-type=0 / copy-pic=1 Default : Yes Forced : No Color range : Limited Color primaries : BT.2020 Matrix coefficients : BT.2020 non-constant DURATION : 00:00:54.375000000 HANDLER_NAME : VideoHandler Mastering display color primaries : R: x=0.680000 y=0.320000, G: x=0.265000 y=0.690000, B: x=0.150000 y=0.060000, White point: x=0.312700 y=0.329000 Mastering display luminance : min: 0.0001 cd/m2, max: 1000.0000 cd/m2 Maximum Content Light Level : 1000 cd/m2 Maximum Frame-Average Light Level : 400 cd/m2
|
|
|
|
|
|
#4 | Link |
|
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Is the log showing any errors? I don't see the transfer in the resulting file. I know the naming changed some revisions back. If you want to be safe you can try the integers:
colorprim=9:transfer=16:colormatrix=9 The mkv container also has such flags which you may want to add (using mkvmerge, mkvpropedit or MkvToolNix GUI's Header Editor). (I don't remember if/how ffmpeg does it.) Last edited by sneaker_ger; 26th January 2018 at 21:29. |
|
|
|
|
|
#6 | Link | |
|
Registered User
Join Date: Jan 2018
Posts: 2
|
Quote:
So thanks you both for your help on this. |
|
|
|
|
|
|
#7 | Link |
|
Registered User
Join Date: Jan 2007
Posts: 10
|
Adding colorprim=9:transfer=16:colormatrix=9 into the mkv container header with the MKVToolNix GUI Header Editor worked for me. Thank you!
Edit - Here's the mkvpropedit command: Code:
mkvpropedit --edit track:1 -s colour-primaries=9 -s colour-transfer-characteristics=16 -s colour-matrix-coefficients=9 output.mkv Last edited by agentusa; 28th January 2018 at 06:13. |
|
|
|
|
|
#9 | Link | ||
|
Registered User
Join Date: Mar 2017
Posts: 10
|
how can i preserve the metadata for the display mastering?
Video ID : 1 Format : HEVC Format/Info : High Efficiency Video Coding Format_Commercial_IfAny : HDR10 Format-Profil : Main 10@L5.1@High Codec-ID : V_MPEGH/ISO/HEVC Dauer : 1 h 52 min Bitrate : 48,3 Mb/s Breite : 3 840 Pixel Höhe : 2 160 Pixel Bildseitenverhältnis : 16:9 Modus der Bildwiederholungsrate : konstant Bildwiederholungsrate : 23,976 (24000/1001) FPS ColorSpace : YUV ChromaSubsampling/String : 4:2:0 (Type 2) BitDepth/String : 10 bits Bits/(Pixel*Frame) : 0.243 Stream-Größe : 38,0 GiB (82%) Default : Ja Forced : Nein colour_range : Limited colour_primaries : BT.2020 transfer_characteristics : PQ matrix_coefficients : BT.2020 non-constant MasteringDisplay_ColorPrimaries : Display P3 MasteringDisplay_Luminance : min: 0.0050 cd/m2, max: 4000 cd/m2 MaxCLL : 4491 cd/m2 MaxFALL : 315 cd/m2 Im recompiling from eg 70GB/file down to somewhere around 20GB and want to keep all HDR information like in original. My current commandline is: Code:
ffmpeg -y -i "in.mkv" -analyzeduration 100M -probesize 100M -max_muxing_queue_size 9999 -map 0:v -map 0:a -map 0:s? -c:s copy -c:a copy -pix_fmt yuv420p10le -vf scale=out_color_matrix=bt2020:out_h_chr_pos=0:out_v_chr_pos=0,format=yuv420p10 -c:v libx265 -preset medium -x265-params "high-tier=1:level-idc=5.1:open-gop=1:crf=22:crf-min=5:crf-max=40:aq-mode=1:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084:colormatrix=bt2020nc:hdr=1:hdr=1:info=1:repeat-headers=1:max-cll=0,0:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(12000000,200)" "out.mkv" MasteringDisplay_ColorPrimaries : Display P3 MasteringDisplay_Luminance : min: 0.0200 cd/m2, max: 1200 cd/m2 but as said, I want to have a universal line keeping the input metadata. Edit: FFMPEG Version: Quote:
Quote:
Last edited by Krautmaster; 2nd July 2018 at 16:32. |
||
|
|
|
|
|
#10 | Link | |
|
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
http://x265.readthedocs.io/en/defaul...master-display max-cll 4491,315 http://x265.readthedocs.io/en/defaul...option-max-cll You can read about the factors needed in the documentation I linked. Not exactly rocket science. |
|
|
|
|
|
|
#11 | Link |
|
Registered User
Join Date: Mar 2017
Posts: 10
|
thx a lot ...
but can I grab / copy this data from the input video without adding them to my command line? I already found out that i can set maxCLL / FALL that way but it seems like that eg the option -repeat-header in x265 seems not to copy the mastering display data to the output file. Edit. I might need to parse though ffprobe to get these values and to dynamically add them to my commandline if i cant copy it by a command. Any ideas how to optimize my commandline or is it fine anyway? Last edited by Krautmaster; 2nd July 2018 at 16:56. |
|
|
|
|
|
#12 | Link | |
|
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
Correct. --repeat-headers has nothing to do with the input file. |
|
|
|
|
![]() |
|
|