traduceme esto al español: We are going to convert the SDR video (Standard Dynamic Range) to HDR (High Dynamic Range) using ffmpeg.
However, note that this is a "fake" HDR conversion (also known as HDR simulation) because the source is SDR (8-bit, Rec.709 color space).
The target is your ROG Nebula Display which supports HDR (Dolby Vision HDR, 500 nits) and has a wide color gamut (DCI-P3 100%).
Steps:
-
We will convert the SDR video to HDR by applying a color space conversion and setting HDR metadata.
-
We need to upscale the video from 1080p to 1600p (your screen is 2560x1600) but note: the source is 1920x1080 (16:9) and your screen is 16:10 (2560x1600).
We will upscale and then letterbox (or crop) to fit the 16:10 aspect ratio? Actually, we can choose to either:
a) Upscale to 1600p and add black bars (letterbox) to preserve the 16:9 aspect ratio, but then the video won't fill the entire screen.
b) Upscale and crop to 16:10. But that might cut some content.
c) Upscale to 2560x1440 (which is 16:9) and then leave black bars on the top and bottom (since 2560x1440 in a 2560x1600 screen has 160 pixels of black bar on top and bottom).
Since the source is 16:9 and your screen is 16:10, the most common approach is to letterbox (black bars). We can do the upscale and then pad to 2560x1600.
However, note: the video is 1920x1080 -> 16:9. We want to output 2560x1600 (16:10). We can:
- Scale the video to 2560x1440 (which is 16:9) and then add 80 pixels of black on top and bottom to make it 2560x1600.
- But note: the display is HDR capable and we want to simulate HDR. We are going to set the output to HDR10.
However, a word of caution: converting SDR to HDR is not going to give true HDR quality, but it can make the video play in HDR mode and possibly use the wider color gamut.
Steps in ffmpeg:
We are going to:
-
Convert the color space from BT.709 (SDR) to BT.2020 (HDR) and use the PQ (Perceptual Quantizer) transfer function.
-
We will set the mastering display metadata to match your display (DCI-P3, 500 nits).
-
We will set the output to 10-bit for HDR.
The command will have the following steps:
a) Decode the input.
b) Scale the video to 2560x1440 (to preserve the 16:9 aspect ratio) and then pad to 2560x1600.
c) Convert the color from 8-bit BT.709 to 10-bit BT.2020 with PQ, and apply a tone mapping to simulate HDR. We can use the 'hable' or 'mobius' tone mapping to avoid clipping.
d) Set the HDR metadata.
However, note: the source is 8-bit and we are converting to 10-bit. We have to be cautious about banding. We can dither to reduce banding.
Let's break down the command:
-
Input: the file.
-
Video filter chain:
-
Scale to 2560x1440 (using a high-quality scaler, like lanczos or spline)
-
Pad to add black bars to make it 2560x1600: we add 80 pixels on top and 80 on bottom.
-
Convert to HDR: we use the zscale filter for high-quality color conversion and dithering.
We'll use:
zscale=transfer=linear,tonemap=tonemap=hable:desat=0,zscale=transfer=smpte2084:matrix=bt2020nc:primaries=bt2020:range=pc,format=yuv420p10le
But note: the above is for true HDR conversion from SDR. Actually, for fake HDR we are just converting the color space and applying a curve.
Alternatively, we can use:
colorspace=bt2020nc:iall=bt709:ispace=bt709:itrc=bt709:iprimaries=bt709:range=pc:format=yuv420p10le
However, this direct conversion might not be the best. We want to simulate the HDR effect.
Actually, a better approach is to use the tonemap filter to map the SDR range to HDR, and then set the output to HDR.
We can do:
`scale=2560x1440:flags=lanczos, pad=2560:1600:0:80:black, \
zscale=t=linear, tonemap=tonemap=hable:param=0.5:desat=0, \
zscale=t=smpte2084:m=bt2020nc:p=bt2020, format=yuv420p10le`
But note: the input to tonemap must be in linear light. We convert to linear with the first zscale (t=linear). Then we apply the tonemap (which is actually an inverse tonemap to expand the range). Then we convert to PQ and set the color matrix.
However, note: this is an inverse tonemap? Actually, we are doing SDR to HDR, so we are expanding the range. The tonemap filter is usually used to map HDR to SDR. We are going the opposite way.
There isn't a standard way to do SDR to HDR. Instead, we can use the reinhard or hable curves in reverse? Actually, we can use the tonemap filter in reverse by setting tonemap=inverse=1. But note: the tonemap filter in ffmpeg doesn't have an inverse option for all curves.
Alternatively, we can use the lut filters to apply a curve. But that is complex.
Another simpler method: we can convert the color space to BT.2020 and apply the PQ transfer function without any tone mapping. But that would just change the color space and transfer, not actually expand the dynamic range.
Since we are faking HDR, we can try to apply a curve to expand the brightness. We can use the gamma filter? But note: HDR uses PQ which is non-linear.
I found a method that uses:
eq=gamma=0.7:saturation=1.2
and then convert to HDR color space. But that is not accurate.
After research, a common approach for SDR to HDR conversion is:
`zscale=rin=709:r=full,format=gbrpf32le, \
zscale=r=full,tonemap=tonemap=linear:param=1.0,zscale=rin=2020_ncl:r=limited:transfer=smpte2084:matrix=2020_ncl, \
format=yuv420p10le`
But note: this is not standard.
Actually, the most straightforward method is to set the output color space to HDR and hope the player or TV will do the mapping. But that might not look good.
Given the complexity and the fact that true HDR conversion from SDR is not possible, we are going to do:
We'll use:
`scale=2560x1440:flags=lanczos, pad=2560:1600:0:80:black, \
colorspace=bt2020nc:iall=bt709:ispace=bt709:itrc=bt709:iprimaries=bt709:range=pc:format=yuv420p10le, \
setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc`
But note: the colorspace filter does not convert the transfer function to PQ. It only does the matrix conversion. We have to set the transfer function separately? Actually, we set the transfer function in the setparams filter.
However, the colorspace filter can also convert the transfer? The itrc is the input transfer and the trc is the output transfer? We are not setting the output transfer in the colorspace filter. We are setting the output transfer in the setparams for the metadata, but the pixel values are still in the original gamma (BT.709). So we need to convert the gamma curve.
We can use the colormatrix and gamma filters? But that is complex.
Alternatively, we can use the zscale filter to do both:
`zscale=transferin=bt709:transfer=smpte2084, \
zscale=matrixin=bt709:matrix=bt2020nc:primariesin=bt709:primaries=bt2020, \
format=yuv420p10le`
But note: the zscale filter does not support transfer function conversion? Actually, it does.
According to the ffmpeg documentation, zscale supports transfer and primaries conversion.
So we can do:
`scale=2560x1440:flags=lanczos, pad=2560:1600:0:80:black, \
zscale=t=smpte2084:m=bt2020nc:p=bt2020, format=yuv420p10le`
But wait, we are not specifying the input color space? We have to set the input color space for zscale.
We can set:
zscale=rin=tv:tin=bt709:min=bt709:pin=bt709: t=smpte2084:m=bt2020nc:p=bt2020, format=yuv420p10le
However, the zscale filter doesn't have an option for input transfer? It has transferin and transfer.
So:
zscale=transferin=bt709:transfer=smpte2084:matrixin=bt709:matrix=bt2020nc:primariesin=bt709:primaries=bt2020, format=yuv420p10le
This will convert the transfer function from BT.709 to SMPTE2084 (PQ), and the matrix from BT.709 to BT.2020 non-constant luminance, and the primaries from BT.709 to BT.2020.
But note: this is a direct conversion without any tone mapping. The brightness values will be mapped linearly? Actually, the transfer function conversion will map the gamma curve of BT.709 to the PQ curve. This is not the same as expanding the dynamic range. It will just change the gamma curve and color space.
The result is that the video will look very dark because the PQ curve is designed for a much higher dynamic range.
To avoid that, we need to apply an expansion of the dynamic range. We can try to adjust the brightness with a curve. We can use the curves filter? But that is complex.
Given the complexity and the fact that fake HDR is not going to be perfect, we might try a simpler method: use the hdr filter to set the metadata and let the display do the mapping? But that doesn't change the pixel data.
Alternatively, we can use the tonemap filter in reverse by using tonemap=tonemap=linear:param=1.0 but in the opposite direction? There isn't a standard way.
After careful thought, I think the best we can do without complex tone mapping is:
-
Upscale and pad as above.
-
Convert to 10-bit and set the color space to BT.2020 and transfer to PQ, but without any dynamic range expansion.
And then set the HDR metadata. The video will be in HDR container but the content is still SDR. The display might recognize it as HDR and switch to HDR mode, and then use its own mapping.
We'll set the metadata for HDR10:
We can set the metadata with the setparams filter and also with the x265-params if we were encoding, but we are not encoding? Actually, we are going to output as H.265? Or we can output as H.264? The source is H.264.
We are going to re-encode? Yes, we are using ffmpeg to convert.
We have to choose an encoder. We can use libx264 for H.264 or libx265 for H.265 (HEVC). HDR is better supported in HEVC.
Let's use HEVC (libx265) because it supports 10-bit and HDR metadata better.
Steps:
-
Decode the input.
-
Apply the video filter chain (upscale, pad, color conversion, and set to 10-bit).
-
Encode with libx265 in 10-bit, and set the HDR metadata.
Command:
ffmpeg -i "input.mkv" \
-vf "scale=1920:-1:flags=lanczos, pad=1920:1200:0:60:black" \
-vf "scale=2560x1440:flags=lanczos, pad=2560:1600:0:80:black, \
zscale=min=bt709:tin=bt709:pin=bt709: npl=100, \
zscale=transfer=smpte2084:matrix=bt2020nc:primaries=bt2020, \
format=yuv420p10le" \
-c:v libx265 -preset medium -crf 18 \
-x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(50000000,0)':max-cll=500,500" \
-c:a copy -c:s copy \
output.mkv
Explanation of the video filter chain:
-
First, we scale to 2560x1440 (lanczos scaling).
-
Then we pad to 2560x1600 (adding 80 pixels top and bottom).
-
Then we use zscale to set the input color space (min=bt709, tin=bt709, pin=bt709) and we set npl=100 (this is the nominal peak luminance, we set to 100 nits which is standard for SDR).
-
Then we convert to the target color space: transfer to smpte2084 (PQ), matrix to bt2020nc, primaries to bt2020, and set the pixel format to yuv420p10le.
The zscale filter with npl=100 will scale the luminance from 0-100 nits to 0-10000 nits? Actually, no. It will map the SDR range to the PQ curve. The PQ curve is absolute (0 to 10000 nits). But without tone mapping, the SDR 100 nits will be mapped to the PQ value for 100 nits. Then when displayed on an HDR display, the display will map the PQ values to its own range (0-500 nits). So the video will look similar to the original? But the metadata we set for the mastering display is 500 nits, so the display will know the content is mastered for 500 nits and adjust accordingly.
However, we are also setting the master-display and max-cll in the x265 parameters.
But note: the zscale filter also has a tonemap option? We are not using it. We are doing a direct conversion.
Alternatively, we can try to use the zscale to do the tone mapping by setting tonemap=linear and tonemap_param? But that is for HDR to SDR.
Given the complexity, we'll go with the direct conversion and setting the metadata.
Steps for the command:
-
Input: the file.
-
Video filters:
scale=2560x1440:flags=lanczos,
pad=2560:1600:0:80:black,
zscale=min=bt709:tin=bt709:pin=bt709:npl=100,
zscale=transfer=smpte2084:matrix=bt2020nc:primaries=bt2020,
format=yuv420p10le
- Encoder: libx265 with parameters for HDR metadata.
But note: the source has a frame rate of 24 FPS. We will preserve that.
The audio and subtitles will be copied.
However, the source has an ASS subtitle. We are copying it, but note that the resolution has changed? The subtitle might be positioned incorrectly. We might need to adjust the subtitle resolution? But the player usually handles that.
Let's write the command:
ffmpeg -i "Sword.of.the.Demon.Hunter.S01E12.Episode.12.1080p.HIDIVE.WEB-DL.JPN.AAC2.0.H.264.ESub-ToonsHub.mkv.mkv" \
-vf "scale=2560:1440:flags=lanczos, pad=2560:1600:0:80:black, \
zscale=min=bt709:tin=bt709:pin=bt709:npl=100, \
zscale=transfer=smpte2084:matrix=bt2020nc:primaries=bt2020, \
format=yuv420p10le" \
-c:v libx265 -preset medium -crf 18 \
-x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(50000000,0)':max-cll=500,500" \
-c:a copy \
-c:s copy \
"output.mkv"
Note: The master-display string is for DCI-P3 (the primaries) and max luminance 500 nits (50000000 in 0.00001 nits). The white point is D65 (15635,16450). The max-cll is 500 nits.
But note: the source is 24 FPS, and the scaling might be heavy. You can adjust the preset to 'fast' if it's too slow.
However, the source is 24 minutes, so it might take a while.
Also, note: the source is 1920x1080 -> scaling to 2560x1440 is an upscale. We are using lanczos which is good.
But the aspect ratio: 1920x1080 is 16:9. We are scaling to 2560x1440 (which is 16:9) and then padding to 2560x1600 (16:10) by adding 80 black pixels on top and bottom.
Let me check: 1440 + 80+80 = 1600, yes.
Step by step:
-
Install ffmpeg (if you haven't). Download from https://ffmpeg.org/ and add to PATH or run from the folder.
-
Open CMD and navigate to the folder containing the input file.
-
Run the above command, but note: the input filename has two .mkv extensions? Actually, the file is named:
"Sword.of.the.Demon.Hunter.S01E12.Episode.12.1080p.HIDIVE.WEB-DL.JPN.AAC2.0.H.264.ESub-ToonsHub.mkv.mkv"
So we have to write exactly that.
- The output file will be "output.mkv" in the same folder.
Important: The conversion might take a long time and use a lot of CPU.
Alternative: if you want to keep the video in H.264, we can try to set the HDR metadata in H.264? But H.264 doesn't support HDR metadata well. So HEVC is better.
If you want H.264, we can use the 10-bit H.264? But it's not widely supported. So I recommend HEVC.
Let me adjust the command to use the correct input and output filenames.
But note: the input file has a long name and spaces? We are using quotes.
We are using:
-i "Sword.of.the.Demon.Hunter.S01E12.Episode.12.1080p.HIDIVE.WEB-DL.JPN.AAC2.0.H.264.ESub-ToonsHub.mkv.mkv"
But the actual file might be named without the double extension? Check the exact name.
Also, the output file: we can name it as we wish.
If you want to adjust the quality, change the -crf value. Lower CRF means better quality (and larger file). For HEVC, 18-28 is a reasonable range. 18 is high quality.
We are copying the audio and subtitles.
Let's write the command again with the exact input filename and a different output filename.
Command:
ffmpeg -i "Sword.of.the.Demon.Hunter.S01E12.Episode.12.1080p.HIDIVE.WEB-DL.JPN.AAC2.0.H.264.ESub-ToonsHub.mkv.mkv" \
-vf "scale=2560:1440:flags=lanczos, pad=2560:1600:0:80:black, \
zscale=min=bt709:tin=bt709:pin=bt709:npl=100, \
zscale=transfer=smpte2084:matrix=bt2020nc:primaries=bt2020, \
format=yuv420p10le" \
-c:v libx265 -preset medium -crf 18 \
-x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(50000000,0)':max-cll=500,500" \
-c:a copy \
-c:s copy \
"Sword.of.the.Demon.Hunter.S01E12.Episode.12.1600p.FakeHDR.HEVC.mkv"
This will create a new file.
Note: the video filter chain is long and we broke it into lines for clarity, but in CMD it must be one line. Alternatively, we can write it without line breaks.
One-line version:
ffmpeg -i "Sword.of.the.Demon.Hunter.S01E12.Episode.12.1080p.HIDIVE.WEB-DL.JPN.AAC2.0.H.264.ESub-ToonsHub.mkv.mkv" -vf "scale=2560:1440:flags=lanczos, pad=2560:1600:0:80:black, zscale=min=bt709:tin=bt709:pin=bt709:npl=100, zscale=transfer=smpte2084:matrix=bt2020nc:primaries=bt2020, format=yuv420p10le" -c:v libx265 -preset medium -crf 18 -x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(50000000,0)':max-cll=500,500" -c:a copy -c:s copy "Sword.of.the.Demon.Hunter.S01E12.Episode.12.1600p.FakeHDR.HEVC.mkv"
But note: the master-display string has spaces? We are enclosing the entire -x265-params string in double quotes and the master-display value in single quotes inside. This should work in CMD.
If you have any issues with the command, you might need to adjust the quotes or escape characters.
Also, note: the npl=100 in the first zscale sets the nominal peak of the input to 100 nits. This is important for the conversion.
Finally, I must emphasize: this is a fake HDR conversion. The result might not be as good as true HDR content. But it will trigger the HDR mode on your display and use the wider color gamut.
Let me know if you have any issues.