Skip to content

Instantly share code, notes, and snippets.

@jslpc
Last active April 17, 2024 07:33
Show Gist options
  • Select an option

  • Save jslpc/05830aab28b58f2191c9fda3ded0fe42 to your computer and use it in GitHub Desktop.

Select an option

Save jslpc/05830aab28b58f2191c9fda3ded0fe42 to your computer and use it in GitHub Desktop.
AV1 ffmpeg Encoding - Blade Runner 2049

Reference

Filename: Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.mp4
Frame count: 1063
Start time: 02:16:39.07
End time: 02:17:23.05
Start frame: 196783
End frame: 197837
Exported clip before encoding: Pink Joi Hologram Scene(https://mega.nz/file/Rg8RBJxA#ox5kgGUYfFKGZYMjzP_pzp-DD3dVcz3rlE5CH9mlPmQ)
I decided to leave the end of that yellow/orange scene to test different visuals.
Note that this clip has been compressed a decent bit just for the purpose of linking it here.

BV's Starting ffmpeg Command

ffmpeg \
-ss 00:24:30 \
-to 00:25:15 \
-i "Remux.mkv" \
-c:v libsvtav1 \
-preset 3 \
-crf 16 \
-g 240 \
-pix_fmt yuv420p10le \
-svtav1-params tune=0:film-grain=4:enable-tf=0:scd=1:enable-restoration=0:irefresh-type=2:film-grain-denoise=0:scm=2:enable-overlays=1:enable-qm=1:color-primaries=bt709:transfer-characteristics=bt709:matrix-coefficients=bt709 \
-an CutAV1clip_noaudio.mkv

BV's Suggestions

[change the] pixfmt, color primaries, turn on hdr, etc [settings]
take that as a starting point, read ffmpeg and av1 documentation, see if you can do it

Using ffprobe to get color information

ffprobe -hide_banner -loglevel warning -select_streams v -print_format json -show_frames -read_intervals "%+#1" -show_entries "frame=color_space,color_primaries,color_transfer,side_data_list,pix_fmt" -i Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.mp4

Output:

{
Unsupported codec with id 98314 for input stream 2
    "frames": [
        {
            "pix_fmt": "yuv420p10le",
            "color_space": "bt2020nc",
            "color_primaries": "bt2020",
            "color_transfer": "smpte2084",
            "side_data_list": [
                {
                    "side_data_type": "Mastering display metadata",
                    "red_x": "34000/50000",
                    "red_y": "16000/50000",
                    "green_x": "13250/50000",
                    "green_y": "34500/50000",
                    "blue_x": "7500/50000",
                    "blue_y": "3000/50000",
                    "white_point_x": "15635/50000",
                    "white_point_y": "16450/50000",
                    "min_luminance": "50/10000",
                    "max_luminance": "40000000/10000"
                },
                {
                    "side_data_type": "Content light level metadata",
                    "max_content": 457,
                    "max_average": 179
                }
            ]
        }
    ]
}

We are now going to take all that data, and break it down into groups of <color abbreviation>(<x>, <y>) while leaving off the right side of the in most cases*, so for example we combine red_x "35400/50000"and red_y "14600/50000" into R(35400,14600).

G(13250,34500)B(7500,3000)R(35400,16000)WP(15635,16450)L(40000000, 50)

Adjusted Command (WIP)

High Quality (hopefully) - 0.006 fps

ffmpeg \
-i "Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.mp4" \
-c:v libsvtav1 \
-preset 3 \
-crf 16 \
-g 240 \
-pix_fmt yuv420p10le \
-svtav1-params tune=0:film-grain=4:enable-tf=0:scd=1:enable-restoration=0:enable-hdr=1:irefresh-type=2:film-grain-denoise=0:mastering-display="G(13250,34500)B(7500,3000)R(35400,16000)WP(15635,16450)L(40000000, 50)":scm=2:enable-overlays=1:enable-qm=1:color-primaries=bt2020:transfer-characteristics=smpte2084:matrix-coefficients=bt2020-ncl \
-an \
Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.v1.mp4

Testing (lower quality)

ffmpeg \
-i "Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.mp4" \
-c:v libsvtav1 \
-preset 3 \
-crf 20 \
-g 240 \
-pix_fmt yuv420p10le \
-svtav1-params tune=0:film-grain=4:enable-tf=0:scd=1:enable-restoration=0:enable-hdr=1:irefresh-type=2:film-grain-denoise=0:mastering-display="G(13250,34500)B(7500,3000)R(35400,16000)WP(15635,16450)L(40000000, 50)":scm=2:enable-overlays=1:enable-qm=1:color-primaries=bt2020:transfer-characteristics=smpte2084:matrix-coefficients=bt2020-ncl \
-an \
Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.v2.mp4
General
Complete name : /Users/jake/Movies/Movies/BladeRunner/Joi testing/Pink Joi Testing/Blade.Runner.2049.Pink.Joi.Scene.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/mp41)
File size : 275 MiB
Duration : 26 min 48 s
Overall bit rate : 1 432 kb/s
Frame rate : 24.000 FPS
Movie name : Blade Runner 2049 (2017) 4K
Writing application : Lavf61.1.100
Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main [email protected]@High
HDR format : SMPTE ST 2086, HDR10 compatible
Codec ID : hev1
Codec ID/Info : High Efficiency Video Coding
Duration : 44 s 335 ms
Source duration : 44 s 252 ms
Bit rate : 51.6 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 24.000 FPS
Minimum frame rate : 23.810 FPS
Maximum frame rate : 16 000.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.259
Stream size : 272 MiB (99%)
Source stream size : 272 MiB (99%)
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: 4000 cd/m2
Maximum Content Light Level : 457 cd/m2
Maximum Frame-Average Light Level : 179 cd/m2
Menus : 3
mdhd_Duration : 44335
Codec configuration box : hvcC
Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 44 s 195 ms
Source duration : 44 s 53 ms
Bit rate mode : Constant
Bit rate : 470 kb/s
Channel(s) : 8 channels
Channel layout : C L R Ls Rs Lw Rw LFE
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 2.47 MiB (1%)
Source stream size : 2.47 MiB (1%)
Title : TrueHD Atmos 7.1
Language : English
Default : Yes
Alternate group : 1
Menus : 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment