lisamelton / other_video_transcoding

Other tools to transcode videos.
MIT License
562 stars 26 forks source link

Force bt709? #208

Open vasuvasu opened 1 month ago

vasuvasu commented 1 month ago

is there a way to force a bt709 color primary?

I have a source video that's SDR bt709, but it keeps getting recognized as HDR bt2020 and encoded as such which makes the colors all wild.

If I edit the ffmpeg command and set color primaries to bt709, then everything looks correct in the output. These are the 3 values I'm setting to bt709: -color_primaries:v bt709 -color_trc:v bt709 -colorspace:v bt709

Is there a way to pass this along in the other-transcode command?

lisamelton commented 1 month ago

@vasuvasu Unfortunately, other-transcode.rb doesn't have an API to pass that information to ffmpeg. Your best strategy is to capture the command line other-transcode.rb uses with the --dry-run option, modify that text (which you clearly already know how to do), and then execute that modified output.

I'm curious as to why other-transcode.rb is trying to convert the color. Can you attach a dump from MediaInfo of your problem file?

vasuvasu commented 1 month ago

@lisamelton here's the dump. If you're curious about my use case, I like to take 4K SDR content and downscale them to 1080p SDR for streaming to plex users. This source file is identified correctly in IINA (mpv) as SDR and plays back looking correct on an SDR screen. The only thing missing in the mediainfo dumb that I see is it missing Color primaries, Transfer characteristics, and Matrix coefficients being explicitly set. I tried adding those in using MKVToolNix, but it still gets misidentified by ffmpeg. Maybe I don't know what I'm doing in MKVToolNix though 😂

General
Unique ID                                : 288764974372787127670310053010976562793 (0xD93E1C714705650FE433130A38E45E69)
Complete name                            : file.mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 2.91 GiB
Duration                                 : 26 min 41 s
Overall bit rate                         : 15.6 Mb/s
Frame rate                               : 23.976 FPS
Writing application                      : mkvmerge v84.0 ('Sleeper') 64-bit
Writing library                          : libebml v1.4.5 + libmatroska v1.7.1

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main 10@L5.1@Main
Codec ID                                 : V_MPEGH/ISO/HEVC
Duration                                 : 26 min 41 s
Bit rate                                 : 15.3 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 10 bits
Bits/(Pixel*Frame)                       : 0.077
Stream size                              : 2.86 GiB (98%)
Default                                  : Yes
Forced                                   : No

Audio
ID                                       : 2
Format                                   : E-AC-3
Format/Info                              : Enhanced AC-3
Commercial name                          : Dolby Digital Plus
Codec ID                                 : A_EAC3
Duration                                 : 26 min 41 s
Bit rate mode                            : Constant
Bit rate                                 : 256 kb/s
Channel(s)                               : 6 channels
Channel layout                           : L R C LFE Ls Rs
Sampling rate                            : 48.0 kHz
Frame rate                               : 31.250 FPS (1536 SPF)
Compression mode                         : Lossy
Stream size                              : 48.9 MiB (2%)
Language                                 : English
Service kind                             : Complete Main
Default                                  : Yes
Forced                                   : No
Dialog Normalization                     : -24 dB
compr                                    : -0.28 dB
dmixmod                                  : 3
ltrtcmixlev                              : -3.0 dB
ltrtsurmixlev                            : -3.0 dB
lorocmixlev                              : -3.0 dB
lorosurmixlev                            : -3.0 dB
dialnorm_Average                         : -24 dB
dialnorm_Minimum                         : -24 dB
dialnorm_Maximum                         : -24 dB

Text #1
ID                                       : 3
Format                                   : UTF-8
Codec ID                                 : S_TEXT/UTF8
Codec ID/Info                            : UTF-8 Plain Text
Duration                                 : 26 min 36 s
Bit rate                                 : 120 b/s
Frame rate                               : 0.383 FPS
Count of elements                        : 612
Stream size                              : 23.5 KiB (0%)
Title                                    : English [SDH]
Language                                 : English
Default                                  : No
Forced                                   : No
lisamelton commented 1 month ago

@vasuvasu Thanks. It seems your input file is 10-bit video with no color information specified. Which means other-transcode.rb assumes the input must be bt709. This is normally a safe assumption based on the bit depth and resolution. I'm guessing this is a download from Uncle Torrance, right? Anyway, I'll take a look at the code and see if there's a way to make an exception for this case.