View Full Version : Looking to encode 4k content while retaining HDR?
jlw_4049
30th April 2019, 16:05
I'm trying to encode some content and it keeps washing the colors out of the video. I'm not super advanced, but I have been trying to do this with FFMPEG. I can't get MeGui to open any UHD videos properly. I have tried simple launcher but it won't accept -s and -t commands to encode a portion of the video for testing.
Can anyone help me, possibly provide me some sort of work flow to do this correctly/most efficient/effective way possible?
Cary Knoop
30th April 2019, 18:14
Are you watching the video on an HDR enabled system and did you use the proper metadata during encoding?
jlw_4049
30th April 2019, 18:48
Are you watching the video on an HDR enabled system and did you use the proper metadata during encoding?I'm not sure how to do the meta data at all
Sent from my SM-G965U1 using Tapatalk
sneaker_ger
30th April 2019, 23:01
Unfortunately, ffmpeg still does not automatically copy the metadata required for players to detect HDR content. You can do this manually by looking up the source parameters via e.g. MediaInfo and then add them into your ffmpeg command line (with libx265).
E.g. from the source viewed in MediaInfo:
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
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.0001 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 1000 cd/m2
Maximum Frame-Average Light Level : 400 cd/m2
This translates to:
ffmpeg -i "source.mkv" -color_range tv -color_primaries 9 -color_trc 16 -colorspace 9 -c:v libx265 -x265-params "chromaloc=2:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1):max-cll=1000,400:hdr-opt=1" "output.mkv"
Luckily, many sources use very similar or even identical parameters so you can get away with copy&paste quite often. Compare the source with your output in MediaInfo to check if you got it right. (With -frames:v 10 ffmpeg will only encode the first 10 frames so you can play with the options before you encode the full movie.)
Note that this example is "static" HDR10/PQ. Not Dolby Vision or the dynamic HDR10+.
Read:
https://x265.readthedocs.io/en/default/cli.html#vui-video-usability-information-options (Read here on how to calculate the master-display values, and e.g. that "BT.2020 non-constant"="9".)
https://en.wikipedia.org/wiki/DCI-P3#System_colorimetry (parameters of "Display P3", same as the --master-display example in the x265 docs (https://x265.readthedocs.io/en/default/cli.html#cmdoption-master-display).)
https://trac.ffmpeg.org/wiki/Encode/H.265#PassingOptions (how to use libx265 in ffmpeg in general)
https://forum.doom9.org/showthread.php?t=174491
jlw_4049
30th April 2019, 23:41
Thank you for the in depth reply. Do you use AviSynth to crop black bars away with FFMPEG? I can't seem to figure out how to get it to work. I'm used to using MeGui to encode with and this is a whole other level of learning for me.
sneaker_ger
1st May 2019, 08:36
ffmpeg has a cropping filter.
E.g. if you want to crop 240 pixels each from top and bottom:
-vf "crop=w=in_w:h=in_h-2*240"
Or you can enter absolute numbers (e.g. crop to 3840x1600):
-vf "crop=w=3840:h=1600"
https://ffmpeg.org/ffmpeg-filters.html#crop
(But you can use AviSynth+ if you want, too. The non-+ AviSynth doesn't natively support 10 bit so I wouldn't recommend it for working on 4K/HDR/10 bit content.)
jlw_4049
1st May 2019, 16:25
The CLI is a little over whelming for me. I have spent the last couple days getting the basics down, but when it comes to all those colors I get lost without copy and pasting.
I have however, been able to make StaxRip work for me quite well actually to encode the 4k. I would love to be able to do it in MeGui, however it doesn't seem to work as easily/as well without manually inputting everything. At that point I might as well continue learning the CLI of FFMPEG.
I do appreciate all the help you have given me so far.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.