As an update to the recommendation in the video, instead of the 291 value for "npl," it is more accurate to use the "MaxFALL" value from the video's metadata. This can be found in the video's properties in decent players or MediaInfo. What's more, it is better not to alter the "param" value, setting it to the default of 0.5 or removing it altogether. Indeed, because going from HDR to SDR may be termed a "lossy" operation, going from more to less, and there being varying recommendations and techniques, there is not one right way of doing it, there will be loss, and it's more a matter of achieving what looks decent. That said, we can get excellent results, but it takes a bit of adjustment and patience.
@@Gett37 You can find it in the MediaInfo tool or MPC-HC player; I think FFmpeg too. Having said that, I recommend using npl=203 for the time being. MaxFALL doesn't seem to give the right results. I forgot about this comment, so thanks for bringing it up. I'll have to update it.
@@GeoffreyAngapa In windows 11 Display settings -> HDR there is a slider "HDR content bightness" from 0 to 100, with 0 all bright sections are getting white-clipped, with 100 there will be no white at all, everything will be dull. Effect is kinda similar to npl - you have to choose what value fits your needs best
@@Gett37 So, it's similar to npl, but normalised to the 0-100 range. I saw that, in the latest version of MPC-HC, one of the video renderers is using that Windows settting to control the adjustment. I'm still on Windows 10 for now. I think different tools are using their own scales, but there are standardised ways of doing it. The fmtconv documentation (for AviSynth and VapourSynth) has insightful information. Indeed, it does a better job than zscale.
@@Gett37 According to the zscale/zimg source code, npl is a double, or 64-bit floating-point value. So the range is quite vast. I tested it now in FFmpeg: it seems to work from 1 to ridiculously high numbers; but by 5,000 or 10,000, the picture is completely dark. github.com/sekrit-twc/zimg/blob/master/src/zimg/api/zimg.h
Cool job! I'm converting the mkv to mkv with tonemap but there is a small issue with framerate. Look here: 'ffmpeg first slice in a frame missing'. What should I do that?
@@adamfeicht8979 If I remember correctly, that error sometimes comes up depending on the source, perhaps owing to corruption. Are there artefacts in the result, or has the frame rate changed?
@@adamfeicht8979 It seems this happens with files that have been cut in such a way that keyframes are missing, or is some problem with the container or the HEVC decoder in FFmpeg. What you can do is, using MKVToolNix, remux the original file and try encoding from that. If the source has been cut, go back to the source's source if possible. Also, perhaps the FFmpeg MOV muxer is causing the issue. So, use MKV or MP4 and see if that makes a difference. I agree this is an obscure issue and there are various places where it could be coming from.
@@adeez1419 Yes, it will work with MKV and other files. I used MP4 as an example because it is common. If you are encoding with x264/5, add a slower -preset for better quality: I left that out to keep it simple.
It depends on the CPU and encoder settings, such as the x264 preset. I did a quick test, and on my Ryzen 3 2200G with four cores and the x264 normal preset, it runs at about 18 fps, meaning it would take a bit longer than the length of the film. Encoding normally, without tone mapping, runs at about 32 fps on x264 normal. In short, it will take longer than normal encoding but not by a massive amount. If your computer is faster than mine, it should be quicker than the film's length: less than two hours. Of course, using a slower encoding preset, which is recommended, will take more time.
thanks man for your effort my problem is that I followed every step but there is no (final.mp4 file). When I opened the ffmpeg.bat file at the end, it opened and closed quickley unlike yours, and at the end there is no (final.mp4 file)
@@adeez1419 You're welcome. When it opens and closes quickly, it means something is not right in the script, perhaps a typo or an invalid setting. To find the problem, add the word "pause" (without quotes) on a new line at the end of the ffmpeg.bat file. Run it again and this time you should be able to see what the error was. Post it here and we'll see if we can get to the bottom of it.
@@adeez1419 One more thing I remembered. If your source video has spaces in the filename, that could be the problem. Simply use quotes around the filename: "My Movie File.mkv"
@@GeoffreyAngapa I tried using quotes, but it didn`t work. I added the word "pause" at the end, and this is what it says: [out#0/mp4 @ 0000028f4acee7c0] Error opening output FINAL.mp4: Permission denied Error opening output file FINAL.mp4. Error opening output files: Permission denied
@@adeez1419 I see. What's happening is that FFmpeg is trying to create the FINAL.mp4 file but doesn't have write permission to that directory. For example, it could be the root of the C: drive. Try moving the files to another folder, such as Desktop, Documents, or another drive. If that doesn't work, add the full file paths to the script (enclosing them in quotes if they've got spaces): "C:\My Folder\ffmpeg.exe" -i "C:\My Folder\Video.mkv" [SCRIPT DETAILS HERE] "C:\My Folder\FINAL.mkv" Then, run the ffmpeg.bat with administrator privileges, by right-clicking and then "Run as administrator." Hopefully, that should work, but it's simpler if you can use a directory where there is write permission by default.
@@Vintexx20 There are methods: it is known as inverse tone mapping, and the ITU-R has published recommendations. However, I am not sure how to do it, and as far as I know, it is not possible in FFmpeg at present. One would likely need to use colour-grading software, such as DaVinci Resolve, and I think the process would likely take more work, since one is going from less to more information.
You have to mention that this command is not the "be-all and-all" that everybody searches for - for example the npl value of 291 can be to "dark" for some content so it needs to be set for example to 100 and param=0.6 for the reinhard tone map maybe can also be set in .1 increments. Uunfortunately there is not "the HDR" but just a bunch of wild parameters which can be all over the place
@@BlackCrow105 I agree, and have learnt more since making the video. Back then, I took the 291 value from an ITU-R recommendation, which, I thought, was supposed to match 90% of the maximum luminance of a typical SDR screen; but I now realise that was likely an incorrect interpretation, and that it's better to take the value from the HDR metadata. Also, I find that 100 is too bright for Reinhard and just as arbitrary. My current solution is to set NPL to the MaxFALL value from the video's metadata, and remove the param value altogether (the default is 0.5). Against 4K Lord of the Rings, it works well, coming close to the official SDR; but as I said, I'm still learning and trying to reach a better solution myself. There's also DGHdrToSdr for VapourSynth, but that's another topic and there are even more parameters. Thanks for the comment. I'll try to add updated guidance in the description or a pinned comment.
It is better, certainly. From what I read, most well-restored 4K films are superior to the 1080p versions. Then, 10-bit colour depth helps a lot, particularly with banding. (Also, 2010-era BluRays were often done quite poorly from old HD masters.) The thing is, not everyone has 4K TVs and displays at present, and doing a process like this, or using a player that can tone map, makes it possible to use a 2160p HDR source and get a quality 1080p version. Admittedly, it may be difficult to match an official copy exactly because colour grading might have been done on a scene-by-scene basis, but quite good results can be achieved.
@@NicolasSilvaVasault Good question. Ideally, one shouldn't because it lowers quality and is not reversible. Also, though in colloquial parlance it is often spoken of as "HDR to SDR," this is only one part, luminance; there is also the going from a bigger colour space (BT.2020) to a smaller (BT.709), losing information in the process. I think it boils down to compatibility: many don't have 4K, HDR-capable TVs, in which case, one may wish to create an SDR version from that file. For example, our TV at home only supports up to 1080p, H.264, High, Level 4.1. Another consideration is that, if one is aiming for a 1080p target, the best sources of a film today are usually the 4K versions. Older, 2008-era Blu-rays are frequently terrible. So, using the 4K, which has hopefully been restored from the original camera negative, one can put together a high-quality, legacy encode.
@@NicolasSilvaVasault If it's been converted, as shown here, the main difference should be a narrower range of luminance; a diminished ability to show very bright and dark areas in the same scene, while retaining detail. And the dark details start getting lost, or the bright details. (In downwards tone mapping, the challenge is choosing the right curve that maps the bigger range to a smaller; each has a different trade-off.) There is also the loss in colour accuracy. To be honest, though, I haven't seen HDR content on an HDR screen, so I don't know how HDR properly looks like in practice.
As an update to the recommendation in the video, instead of the 291 value for "npl," it is more accurate to use the "MaxFALL" value from the video's metadata. This can be found in the video's properties in decent players or MediaInfo. What's more, it is better not to alter the "param" value, setting it to the default of 0.5 or removing it altogether. Indeed, because going from HDR to SDR may be termed a "lossy" operation, going from more to less, and there being varying recommendations and techniques, there is not one right way of doing it, there will be loss, and it's more a matter of achieving what looks decent. That said, we can get excellent results, but it takes a bit of adjustment and patience.
I cant get max-fall with ffmpeg or exiftool?
@@Gett37 You can find it in the MediaInfo tool or MPC-HC player; I think FFmpeg too. Having said that, I recommend using npl=203 for the time being. MaxFALL doesn't seem to give the right results. I forgot about this comment, so thanks for bringing it up. I'll have to update it.
Thank you @Geoffrey ! I was getting too bright video by using other ffmpeg commands but yours is better.
@@Gett37 Fantastic! Next time, try npl=203 and see how that looks. For now, I recommend 203.
@@GeoffreyAngapa In windows 11 Display settings -> HDR there is a slider "HDR content bightness" from 0 to 100, with 0 all bright sections are getting white-clipped, with 100 there will be no white at all, everything will be dull. Effect is kinda similar to npl - you have to choose what value fits your needs best
@@Gett37 So, it's similar to npl, but normalised to the 0-100 range. I saw that, in the latest version of MPC-HC, one of the video renderers is using that Windows settting to control the adjustment. I'm still on Windows 10 for now. I think different tools are using their own scales, but there are standardised ways of doing it. The fmtconv documentation (for AviSynth and VapourSynth) has insightful information. Indeed, it does a better job than zscale.
@@GeoffreyAngapa I haven't found a range in which npl should be set. What are minimum and maximum values?
@@Gett37 According to the zscale/zimg source code, npl is a double, or 64-bit floating-point value. So the range is quite vast. I tested it now in FFmpeg: it seems to work from 1 to ridiculously high numbers; but by 5,000 or 10,000, the picture is completely dark.
github.com/sekrit-twc/zimg/blob/master/src/zimg/api/zimg.h
Cool job! I'm converting the mkv to mkv with tonemap but there is a small issue with framerate. Look here: 'ffmpeg first slice in a frame missing'. What should I do that?
@@adamfeicht8979 If I remember correctly, that error sometimes comes up depending on the source, perhaps owing to corruption. Are there artefacts in the result, or has the frame rate changed?
@@GeoffreyAngapa The original source is clean and runs correctly but after the converting to mov (sorry, wrong typed 'mkv') it jumps a bit. The framerate runs 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 11, 11, 12, 13, 14, 15, 16, 17, 18, 18, 20, 20, 21, ...
The source:
1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format-Profil : Main 10@L5.1@High
HDR format : SMPTE ST 2086, HDR10 compatible
Codec-ID : V_MPEGH/ISO/HEVC
Dauer : 1 h 45 min
Bitrate : 58,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
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.293
Stream-Größe : 43,1 GiB (87%)
Default : Ja
Forced : Nein
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 : 456 cd/m2
Maximum Frame-Average Light Level : 85 cd/m2
@@adamfeicht8979 It seems this happens with files that have been cut in such a way that keyframes are missing, or is some problem with the container or the HEVC decoder in FFmpeg. What you can do is, using MKVToolNix, remux the original file and try encoding from that. If the source has been cut, go back to the source's source if possible. Also, perhaps the FFmpeg MOV muxer is causing the issue. So, use MKV or MP4 and see if that makes a difference. I agree this is an obscure issue and there are various places where it could be coming from.
does it work with .mkv files or is it only for .mp4?
@@adeez1419 Yes, it will work with MKV and other files. I used MP4 as an example because it is common. If you are encoding with x264/5, add a slower -preset for better quality: I left that out to keep it simple.
How long does this process usually take for a stand length movie? Thanks.
It depends on the CPU and encoder settings, such as the x264 preset. I did a quick test, and on my Ryzen 3 2200G with four cores and the x264 normal preset, it runs at about 18 fps, meaning it would take a bit longer than the length of the film. Encoding normally, without tone mapping, runs at about 32 fps on x264 normal.
In short, it will take longer than normal encoding but not by a massive amount. If your computer is faster than mine, it should be quicker than the film's length: less than two hours. Of course, using a slower encoding preset, which is recommended, will take more time.
thanks man for your effort
my problem is that I followed every step but there is no (final.mp4 file).
When I opened the ffmpeg.bat file at the end, it opened and closed quickley unlike yours, and at the end there is no (final.mp4 file)
@@adeez1419 You're welcome. When it opens and closes quickly, it means something is not right in the script, perhaps a typo or an invalid setting. To find the problem, add the word "pause" (without quotes) on a new line at the end of the ffmpeg.bat file. Run it again and this time you should be able to see what the error was. Post it here and we'll see if we can get to the bottom of it.
@@adeez1419 One more thing I remembered. If your source video has spaces in the filename, that could be the problem. Simply use quotes around the filename: "My Movie File.mkv"
@@GeoffreyAngapa I tried using quotes, but it didn`t work.
I added the word "pause" at the end, and this is what it says:
[out#0/mp4 @ 0000028f4acee7c0] Error opening output FINAL.mp4: Permission denied
Error opening output file FINAL.mp4.
Error opening output files: Permission denied
@@adeez1419 I see. What's happening is that FFmpeg is trying to create the FINAL.mp4 file but doesn't have write permission to that directory. For example, it could be the root of the C: drive.
Try moving the files to another folder, such as Desktop, Documents, or another drive. If that doesn't work, add the full file paths to the script (enclosing them in quotes if they've got spaces):
"C:\My Folder\ffmpeg.exe" -i "C:\My Folder\Video.mkv" [SCRIPT DETAILS HERE] "C:\My Folder\FINAL.mkv"
Then, run the ffmpeg.bat with administrator privileges, by right-clicking and then "Run as administrator." Hopefully, that should work, but it's simpler if you can use a directory where there is write permission by default.
can i convert my SDR videos into crispy HDR colorfull videos?
@@Vintexx20 Not with this method :)
@@GeoffreyAngapa any other method ? please tell me
@@Vintexx20 There are methods: it is known as inverse tone mapping, and the ITU-R has published recommendations. However, I am not sure how to do it, and as far as I know, it is not possible in FFmpeg at present. One would likely need to use colour-grading software, such as DaVinci Resolve, and I think the process would likely take more work, since one is going from less to more information.
You have to mention that this command is not the "be-all and-all" that everybody searches for - for example the npl value of 291 can be to "dark" for some content so it needs to be set for example to 100 and param=0.6 for the reinhard tone map maybe can also be set in .1 increments. Uunfortunately there is not "the HDR" but just a bunch of wild parameters which can be all over the place
@@BlackCrow105 I agree, and have learnt more since making the video. Back then, I took the 291 value from an ITU-R recommendation, which, I thought, was supposed to match 90% of the maximum luminance of a typical SDR screen; but I now realise that was likely an incorrect interpretation, and that it's better to take the value from the HDR metadata. Also, I find that 100 is too bright for Reinhard and just as arbitrary.
My current solution is to set NPL to the MaxFALL value from the video's metadata, and remove the param value altogether (the default is 0.5). Against 4K Lord of the Rings, it works well, coming close to the official SDR; but as I said, I'm still learning and trying to reach a better solution myself. There's also DGHdrToSdr for VapourSynth, but that's another topic and there are even more parameters.
Thanks for the comment. I'll try to add updated guidance in the description or a pinned comment.
@@GeoffreyAngapa It´s a really interesting but also exhausting hobby - sometimes i think it´s some kind of black magic 😆
@@BlackCrow105 A satisfying but headache-inducing hobby! That's encoding :)
4K HDR is stronger and better than 1080P 4K HDR is 2160P
It is better, certainly. From what I read, most well-restored 4K films are superior to the 1080p versions. Then, 10-bit colour depth helps a lot, particularly with banding. (Also, 2010-era BluRays were often done quite poorly from old HD masters.)
The thing is, not everyone has 4K TVs and displays at present, and doing a process like this, or using a player that can tone map, makes it possible to use a 2160p HDR source and get a quality 1080p version. Admittedly, it may be difficult to match an official copy exactly because colour grading might have been done on a scene-by-scene basis, but quite good results can be achieved.
why would anyone lower their videos quality to sdr? i don't get it
@@NicolasSilvaVasault Good question. Ideally, one shouldn't because it lowers quality and is not reversible. Also, though in colloquial parlance it is often spoken of as "HDR to SDR," this is only one part, luminance; there is also the going from a bigger colour space (BT.2020) to a smaller (BT.709), losing information in the process.
I think it boils down to compatibility: many don't have 4K, HDR-capable TVs, in which case, one may wish to create an SDR version from that file. For example, our TV at home only supports up to 1080p, H.264, High, Level 4.1.
Another consideration is that, if one is aiming for a 1080p target, the best sources of a film today are usually the 4K versions. Older, 2008-era Blu-rays are frequently terrible. So, using the 4K, which has hopefully been restored from the original camera negative, one can put together a high-quality, legacy encode.
@@GeoffreyAngapa both my tv and monitor are compatible with hdr, how does hdr looks on an sdr screen?
@@NicolasSilvaVasault If it's been converted, as shown here, the main difference should be a narrower range of luminance; a diminished ability to show very bright and dark areas in the same scene, while retaining detail. And the dark details start getting lost, or the bright details. (In downwards tone mapping, the challenge is choosing the right curve that maps the bigger range to a smaller; each has a different trade-off.) There is also the loss in colour accuracy. To be honest, though, I haven't seen HDR content on an HDR screen, so I don't know how HDR properly looks like in practice.
@@GeoffreyAngapa ohhh i see now, thanks