Opened 6 weeks ago

Last modified 6 weeks ago

#11309 new defect

ffmpeg 7.1 fails to write color_primaries and color_trc

Reported by: wywh Owned by:
Priority: normal Component: undetermined
Version: 7.1 Keywords: color_primaries color_trc
Cc: Jérôme Martinez, MasterQuestionable Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

In ffmpeg 7.0.2_2 and 4.4.5_0 the command below works as expected but in 7.1 it fails to write color_primaries and color_trc.

There is also a new alert:

"Codec AVOption gop_timecode (MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some decoder which was not actually used for any stream."

ffmpeg7 -i input.mp4 -c:v libx265 -crf 28 -preset medium -pix_fmt yuv420p10le -profile:v main10 -color_range 1 -color_primaries:v bt470bg -color_trc:v bt709 -colorspace:v smpte170m -timecode 00:00:00:00 -tag:v hvc1 -c:a aac -b:a 128k ffmpeg7.mp4
ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 16.0.0 (clang-1600.0.26.3)
  configuration: --cc=/usr/bin/clang --datadir=/opt/local/libexec/ffmpeg7/share/data --docdir=/opt/local/libexec/ffmpeg7/share/doc --progs-suffix=7 --prefix=/opt/local/libexec/ffmpeg7 --enable-audiotoolbox --disable-indev=jack --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libplacebo --disable-libvmaf --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-metal --enable-opencl --disable-outdev=xv --enable-sdl2 --disable-securetransport --enable-videotoolbox --disable-xlib --enable-avfilter --enable-fontconfig --enable-gnutls --enable-lcms2 --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libfribidi --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg --enable-libzvbi --enable-lzma --enable-pthreads --enable-shared --enable-swscale --enable-zlib --enable-libaom --enable-libsvtav1 --arch=x86_64 --enable-x86asm --enable-gpl --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-postproc
  libavutil      59. 39.100 / 59. 39.100
  libavcodec     61. 19.100 / 61. 19.100
  libavformat    61.  7.100 / 61.  7.100
  libavdevice    61.  3.100 / 61.  3.100
  libavfilter    10.  4.100 / 10.  4.100
  libswscale      8.  3.100 /  8.  3.100
  libswresample   5.  3.100 /  5.  3.100
  libpostproc    58.  3.100 / 58.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:02.00, start: 0.000000, bitrate: 1016 kb/s
  Stream #0:0[0x1](und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, progressive), 768x576 [SAR 1:1 DAR 4:3], 863 kb/s, 50 fps, 50 tbr, 12800 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        timecode        : 00:00:00:00
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74), 0 kb/s
      Metadata:
        handler_name    : TimeCodeHandler
        timecode        : 00:00:00:00
[out#0/mp4 @ 0x7f94bba10e80] Codec AVOption gop_timecode (MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some decoder which was not actually used for any stream.
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.6+1-aa7f602f7
x265 [info]: build info [Mac OS X][clang 16.0.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-3.1 (Main tier)
x265 [info]: Thread pool created using 12 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(9 rows)
x265 [warning]: Source height < 720p; disabling lookahead-slices
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 25 / 250 / 40 / 5.00 
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing deblock sao
Output #0, mp4, to 'ffmpeg7.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    timecode        : 00:00:00:00
    encoder         : Lavf61.7.100
  Stream #0:0(und): Video: hevc (hvc1 / 0x31637668), yuv420p10le(tv, smpte170m/unknown/unknown, progressive), 768x576 [SAR 1:1 DAR 4:3], q=2-31, 50 fps, 12800 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        timecode        : 00:00:00:00
        encoder         : Lavc61.19.100 libx265
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.19.100 aac
[out#0/mp4 @ 0x7f94bba10e80] video:190KiB audio:30KiB subtitle:0KiB other streams:0KiB global headers:2KiB muxing overhead: 2.988819%
frame=  100 fps= 87 q=37.4 Lsize=     227KiB time=00:00:01.96 bitrate= 950.1kbits/s speed= 1.7x    
x265 [info]: frame I:      1, Avg QP:30.71  kb/s: 3501.20 
x265 [info]: frame P:     21, Avg QP:31.01  kb/s: 1954.04 
x265 [info]: frame B:     78, Avg QP:36.82  kb/s: 426.02  
x265 [info]: Weighted P-Frames: Y:9.5% UV:9.5%

encoded 100 frames in 1.13s (88.61 fps), 777.66 kb/s, Avg QP:35.54
[aac @ 0x7f94bba7bf40] Qavg: 200.813

In ffmpeg 4.4.5 (and 7.0.2_2) it works:

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -pix_fmt yuv420p10le -profile:v main10 -color_range 1 -color_primaries:v bt470bg -color_trc:v bt709 -colorspace:v smpte170m -timecode 00:00:00:00 -tag:v hvc1 -c:a aac -b:a 128k ffmpeg4.mp4 
ffmpeg version 4.4.5 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 16.0.0 (clang-1600.0.26.3)
  configuration: --prefix=/opt/local --cc=/usr/bin/clang --mandir=/opt/local/share/man --enable-audiotoolbox --disable-indev=jack --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --enable-opencl --disable-outdev=xv --enable-sdl2 --disable-securetransport --enable-videotoolbox --enable-avfilter --enable-avresample --enable-fontconfig --enable-gnutls --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libfribidi --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg --enable-libzvbi --enable-lzma --enable-pthreads --enable-shared --enable-swscale --enable-zlib --enable-libaom --enable-libsvtav1 --arch=x86_64 --enable-x86asm --enable-gpl --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-postproc
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:02.00, start: 0.000000, bitrate: 1016 kb/s
  Stream #0:0(und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, progressive), 768x576 [SAR 1:1 DAR 4:3], 863 kb/s, 50 fps, 50 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      timecode        : 00:00:00:00
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s
    Metadata:
      handler_name    : TimeCodeHandler
      timecode        : 00:00:00:00
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.6+1-aa7f602f7
x265 [info]: build info [Mac OS X][clang 16.0.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-3.1 (Main tier)
x265 [info]: Thread pool created using 12 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(9 rows)
x265 [warning]: Source height < 720p; disabling lookahead-slices
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 25 / 250 / 40 / 5.00 
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing deblock sao
[mp4 @ 0x7f9c5381d800] Application provided duration: -9223372036854775808 / timestamp: -9223372036854775808 is out of range for mov/mp4 format
[mp4 @ 0x7f9c5381d800] pts has no value
Output #0, mp4, to 'ffmpeg4.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    timecode        : 00:00:00:00
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: hevc (hvc1 / 0x31637668), yuv420p10le(tv, smpte170m/bt470bg/bt709, progressive), 768x576 [SAR 1:1 DAR 4:3], q=2-31, 0.02 fps, 12800 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      timecode        : 00:00:00:00
      encoder         : Lavc58.134.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 aac
frame=  100 fps= 88 q=37.4 Lsize=     228kB time=00:00:01.94 bitrate= 960.8kbits/s speed=1.71x    
video:190kB audio:31kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 2.976367%
x265 [info]: frame I:      1, Avg QP:30.71  kb/s: 3501.20 
x265 [info]: frame P:     21, Avg QP:31.01  kb/s: 1954.04 
x265 [info]: frame B:     78, Avg QP:36.82  kb/s: 426.02  
x265 [info]: Weighted P-Frames: Y:9.5% UV:9.5%

encoded 100 frames in 1.12s (89.50 fps), 777.66 kb/s, Avg QP:35.54
[aac @ 0x7f9c53824000] Qavg: 161.075

Like ffprobe below, also MediaInfo reports that ffmpeg 7.1 fails to write color_primaries and color_trc while in ffmpeg 4 output they are written.

ffprobe7 -v error -show_streams input.mp4 | grep color_
color_range=tv
color_space=unknown
color_transfer=unknown
color_primaries=unknown

ffprobe7 -v error -show_streams ffmpeg7.mp4 | grep color_
color_range=tv
color_space=smpte170m
color_transfer=unknown
color_primaries=unknown

ffprobe7 -v error -show_streams ffmpeg4.mp4 | grep color_
color_range=tv
color_space=smpte170m
color_transfer=bt709
color_primaries=bt470bg

Change History (7)

comment:1 by Jérôme Martinez, 6 weeks ago

Cc: Jérôme Martinez added

comment:2 by jeeb, 6 weeks ago

In general please test with the latest master build from f.ex. Btbn's publicly automated builds (although I don't think he has macOS builds @ https://github.com/BtbN/FFmpeg-Builds/releases/tag/latest ). In this case I tested with current master.

This seems to be a general issue regarding when/where these global options get applied, as you can see that the output definition no longer has these color values and if you test other encoders that have color value support you will see those also not writing things out. A workaround for now is to utilize the filter chain to set the required value overrides, as starting with FFmpeg 4.4 the first frame from the filter chain gets automatically utilized for color related configuration. Example: -vf setparams=colorspace=bt709:color_trc=bt709:color_primaries=bt709. Help for the filter can be listed with ffmpeg -h filter=setparams.

comment:3 by jeeb, 6 weeks ago

Note two, both of these AVOptions get applied just fine for the input modules (if you specify them before -i INPUT), working as an override of the input information. Given that the effect of these options is exactly that (overrides of values instead of actually causing any conversions), this is quite matching.

comment:4 by Leo Izen, 6 weeks ago

Seems to me that it's not encoder or muxer dependent. I tried with mpeg4+mp4, ffv1+mkv, and reproduced it on Linux with git master.

It does appear that the tags that are already set in the stream are still written.

comment:5 by Leo Izen, 6 weeks ago

Reproduced by developer: set

in reply to:  4 comment:6 by jeeb, 6 weeks ago

Replying to Leo Izen:

Seems to me that it's not encoder or muxer dependent. I tried with mpeg4+mp4, ffv1+mkv, and reproduced it on Linux with git master.

It does appear that the tags that are already set in the stream are still written.

I did note the same, although I don't blame you not reading my long sentences :)

This seems to be a general issue regarding when/where these global options get applied, as you can see that the output definition no longer has these color values and if you test other encoders that have color value support you will see those also not writing things out.

My most likely guess is that the AVOptions are applied much earlier in the process (see around fftools/cmdutils.c: av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "), before fftools/ffmpeg_enc.c::enc_open gets called. This would also explain why input overriding works, as AVFrame information passing is only done for the encoder. This is more or less verified by commenting out one of the lines in that function setting any of the parameters you are overriding on command line on the output definition side, as that "magically" makes the value propagate.

comment:7 by MasterQuestionable, 6 weeks ago

Cc: MasterQuestionable added

͏    Intended or not: serious regression is the problem.
͏    https://trac.ffmpeg.org/ticket/11238#comment:5

Note: See TracTickets for help on using tickets.