[FFmpeg-devel] ffmpeg-2.1 + colormatrix filter appears broken

David Favor david at davidfavor.com
Tue Nov 12 19:15:34 CET 2013


 > Summary.
 >
 > I have many videos which fail to play on Roku devices.
 >
 > The problem appears to be colormatrix related parameters are NULL.
 >
 > Forcing colormatrix to bt709 allows the video to play + the only way
 > to do this appears to be using x264 options.
 >
 > Problems...
 >
 > 1) videos are missing the following parameters. video plays when these
 >    parameters are set to BT.709 via -x264opts below.
 >
 >    Color primaries                          : NULL
 >    Transfer characteristics                 : NULL
 >    Matrix coefficients                      : NULL
 >
 > 2) ffmpeg -vf colormatrix=src:dst seems to have no idea how to do a
 >    conversion from a null colormatrix to another colormatrix
 >
 > 3) ffmpeg allows incorrect dst colormatrix matching when filter is called...
 >    so -vf colormatrix=bt601:bt709 is accepted, where the mismatch between
 >    src=NULL when src=bt601 should probably throw a mismatch error.
 >
 > The fix is to force setting all the parameters in #1 by passing options to x264...
 >
 >    -x264opts colorprim=bt709:transfer=bt709:colormatrix=bt709:fullrange=off
 >
 > Seems like this might be a bug.
 > _______
 >
 > Here's the clip... (avinfo is a script that filters ffmpeg output)
 >
 > David-Favor-iMac> avinfo broken-cm-bt709.mp4
 > broken-cm-bt709.mp4
 >    Duration: 00:01:00.02, start: 0.000000, bitrate: 1213 kb/s
 >    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1112 kb/s, 23.98 fps, 23.98 tbr, 96k tbn, 47.95 
tbc (default)
 >    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
 >
 > Notice 'yuv420p' instead of most videos which are 'yuv420p(tv, bt709)'.
 >
 > Mediainfo shows key info missing from video.
 >
 > David-Favor-iMac> mediainfo broken-cm-bt709.mp4 | egrep 'Color primaries|Transfer characteristics|Matrix coefficients'
 >
 > The first thing I tried was to simply change the colormatrix + the docs say...
 >
 >    http://ffmpeg.org/ffmpeg-filters.html#colormatrix
 >    Specify the source and destination color matrix. Both values must be specified.
 >
 > So specifying a null src fails as expected...
 >
 > David-Favor-iMac> ffmpeg -y -i broken-cm-bt709.mp4 -c:a copy -threads 0 -c:v libx264 -preset:v veryfast -crf:v 20 -vf colormatrix=:bt709 -r 23.98 
broken-cm-bt709-fixed.mp4
 > ffmpeg version 2.1.0-2013-11-02-57805-g1a6948f Copyright (c) 2000-2013 the FFmpeg developers
 >   built on Nov  2 2013 08:06:01 with gcc 4.8.2 (MacPots gcc48 4.8.2_0)
 >   configuration: --prefix=/david-favor-tools/osx-10.9 --enable-pic --enable-gpl --disable-debug --extra-cflags='-I 
/david-favor-tools/osx-10.9/include -I /opt/local/include' --extra-ldflags='-Wl,-rpath,/david-favor-tools/osx-10.9/lib -Wl,-rpath,/opt/local/lib -L 
/david-favor-tools/osx-10.9/lib -L /opt/local/lib' --enable-version3 --enable-shared --disable-static --enable-ffplay --enable-ffprobe 
--enable-ffserver --enable-runtime-cpudetect --enable-nonfree --enable-zlib --enable-bzlib --enable-openssl --enable-libmp3lame --enable-libfaac 
--enable-libvpx --enable-libtheora --enable-libvorbis --enable-libxvid --enable-libopus --enable-libopenjpeg --enable-libfreetype --enable-libx264 
--enable-postproc --enable-frei0r --enable-libopencore-amrnb --enable-libmodplug --enable-libass --enable-openssl
 >   libavutil      52. 49.100 / 52. 49.100
 >   libavcodec     55. 40.101 / 55. 40.101
 >   libavformat    55. 21.100 / 55. 21.100
 >   libavdevice    55.  5.100 / 55.  5.100
 >   libavfilter     3. 90.100 /  3. 90.100
 >   libswscale      2.  5.101 /  2.  5.101
 >   libswresample   0. 17.104 /  0. 17.104
 >   libpostproc    52.  3.100 / 52.  3.100
 > Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'broken-cm-bt709.mp4':
 >   Metadata:
 >     major_brand     : isom
 >     minor_version   : 512
 >     compatible_brands: isomiso2avc1mp41
 >     encoder         : Lavf55.19.104
 >   Duration: 00:01:00.02, start: 0.000000, bitrate: 1213 kb/s
 >     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1112 kb/s, 23.98 fps, 23.98 tbr, 96k tbn, 47.95 
tbc (default)
 >     Metadata:
 >       handler_name    : VideoHandler
 >     Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
 >     Metadata:
 >       handler_name    : SoundHandler
 > [colormatrix @ 0x7fa9da424d20] [Eval @ 0x7fff50be9110] Undefined constant or missing '(' in ''
 > [colormatrix @ 0x7fa9da424d20] Unable to parse option value ""
 > [colormatrix @ 0x7fa9da424d20] [Eval @ 0x7fff50be9170] Undefined constant or missing '(' in ''
 > [colormatrix @ 0x7fa9da424d20] Unable to parse option value ""
 > [colormatrix @ 0x7fa9da424d20] Error setting option src to value .
 > [Parsed_colormatrix_0 @ 0x7fa9da4230a0] Error applying options to the filter.
 > [AVFilterGraph @ 0x7fa9da4231a0] Error initializing filter 'colormatrix' with args ':bt709'
 > Error opening filters!
 >
 > This works... even though the src (bt601) is bogus (fails to match whatever the null setting is).
 > And colormatrix is still unset 'yuv420p' instead of 'yuv420p(tv, bt709)'
 >
 > David-Favor-iMac> avinfo broken-cm-bt709-fixed.mp4
 > broken-cm-bt709-fixed.mp4
 >    Duration: 00:01:00.22, start: 0.000000, bitrate: 1749 kb/s
 >    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1648 kb/s, 23.98 fps, 23.98 tbr, 19184 tbn, 
47.96 tbc (default)
 >    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
 >
 > The only way colormatrix seems to be effected is to pass options directly to x264, so this works...
 >
 > David-Favor-iMac> ffmpeg -i broken-cm-bt709.mp4 -c:a copy -threads 0 -c:v libx264 -preset:v veryfast -crf:v 20 -x264opts 
colorprim=bt709:transfer=bt709:colormatrix=bt709:fullrange=off -r 23.98 broken-cm-bt709-fixed.mp4
 > ffmpeg version 2.1.0-2013-11-02-57805-g1a6948f Copyright (c) 2000-2013 the FFmpeg developers
 >   built on Nov  2 2013 08:06:01 with gcc 4.8.2 (MacPots gcc48 4.8.2_0)
 >   configuration: --prefix=/david-favor-tools/osx-10.9 --enable-pic --enable-gpl --disable-debug --extra-cflags='-I 
/david-favor-tools/osx-10.9/include -I /opt/local/include' --extra-ldflags='-Wl,-rpath,/david-favor-tools/osx-10.9/lib -Wl,-rpath,/opt/local/lib -L 
/david-favor-tools/osx-10.9/lib -L /opt/local/lib' --enable-version3 --enable-shared --disable-static --enable-ffplay --enable-ffprobe 
--enable-ffserver --enable-runtime-cpudetect --enable-nonfree --enable-zlib --enable-bzlib --enable-openssl --enable-libmp3lame --enable-libfaac 
--enable-libvpx --enable-libtheora --enable-libvorbis --enable-libxvid --enable-libopus --enable-libopenjpeg --enable-libfreetype --enable-libx264 
--enable-postproc --enable-frei0r --enable-libopencore-amrnb --enable-libmodplug --enable-libass --enable-openssl
 >   libavutil      52. 49.100 / 52. 49.100
 >   libavcodec     55. 40.101 / 55. 40.101
 >   libavformat    55. 21.100 / 55. 21.100
 >   libavdevice    55.  5.100 / 55.  5.100
 >   libavfilter     3. 90.100 /  3. 90.100
 >   libswscale      2.  5.101 /  2.  5.101
 >   libswresample   0. 17.104 /  0. 17.104
 >   libpostproc    52.  3.100 / 52.  3.100
 > Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'broken-cm-bt709.mp4':
 >   Metadata:
 >     major_brand     : isom
 >     minor_version   : 512
 >     compatible_brands: isomiso2avc1mp41
 >     encoder         : Lavf55.19.104
 >   Duration: 00:01:00.02, start: 0.000000, bitrate: 1213 kb/s
 >     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1112 kb/s, 23.98 fps, 23.98 tbr, 96k tbn, 47.95 
tbc (default)
 >     Metadata:
 >       handler_name    : VideoHandler
 >     Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
 >     Metadata:
 >       handler_name    : SoundHandler
 > File 'broken-cm-bt709-fixed.mp4' already exists. Overwrite ? [y/N] y
 > [libx264 @ 0x7fe15080c400] using SAR=1/1
 > [libx264 @ 0x7fe15080c400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
 > [libx264 @ 0x7fe15080c400] profile High, level 3.1
 > [libx264 @ 0x7fe15080c400] 264 - core 138 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 
ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 
deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=4 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 
constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=23 scenecut=40 
intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
 > Output #0, mp4, to 'broken-cm-bt709-fixed.mp4':
 >   Metadata:
 >     major_brand     : isom
 >     minor_version   : 512
 >     compatible_brands: isomiso2avc1mp41
 >     encoder         : Lavf55.21.100
 >     Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 19184 tbn, 23.98 tbc (default)
 >     Metadata:
 >       handler_name    : VideoHandler
 >     Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 96 kb/s (default)
 >     Metadata:
 >       handler_name    : SoundHandler
 > Stream mapping:
 >   Stream #0:0 -> #0:0 (h264 -> libx264)
 >   Stream #0:1 -> #0:1 (copy)
 > Press [q] to stop, [?] for help
 > frame= 1444 fps=132 q=-1.0 Lsize=   12740kB time=00:01:00.13 bitrate=1735.6kbits/s dup=5 drop=0
 > video:11997kB audio:703kB subtitle:0 global headers:0kB muxing overhead 0.308973%
 > [libx264 @ 0x7fe15080c400] frame I:13    Avg QP:10.82  size: 17746
 > [libx264 @ 0x7fe15080c400] frame P:775   Avg QP:16.92  size: 13198
 > [libx264 @ 0x7fe15080c400] frame B:656   Avg QP:17.75  size:  2782
 > [libx264 @ 0x7fe15080c400] consecutive B-frames: 26.8% 37.1%  2.3% 33.8%
 > [libx264 @ 0x7fe15080c400] mb I  I16..4: 62.5% 28.2%  9.3%
 > [libx264 @ 0x7fe15080c400] mb P  I16..4: 18.0% 10.8%  0.7%  P16..4: 23.0% 10.9%  5.1%  0.0%  0.0%    skip:31.4%
 > [libx264 @ 0x7fe15080c400] mb B  I16..4:  1.3%  0.4%  0.0%  B16..8: 15.8%  3.5%  0.3%  direct: 4.2%  skip:74.4%  L0:33.3% L1:53.2% BI:13.5%
 > [libx264 @ 0x7fe15080c400] 8x8 transform intra:35.7% inter:39.8%
 > [libx264 @ 0x7fe15080c400] coded y,uvDC,uvAC intra: 26.2% 33.5% 6.5% inter: 8.3% 10.3% 0.5%
 > [libx264 @ 0x7fe15080c400] i16 v,h,dc,p: 61% 22% 13%  5%
 > [libx264 @ 0x7fe15080c400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 23% 29%  3%  4%  5%  4%  4%  5%
 > [libx264 @ 0x7fe15080c400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 22% 18%  5%  5%  6%  5%  6%  5%
 > [libx264 @ 0x7fe15080c400] i8c dc,h,v,p: 66% 15% 16%  2%
 > [libx264 @ 0x7fe15080c400] Weighted P-Frames: Y:8.0% UV:5.7%
 > [libx264 @ 0x7fe15080c400] kb/s:1632.05
 >
 > Now colormatrix is set + the video plays on Roku devices...
 >
 > avinfo broken-cm-bt709-fixed.mp4
 > broken-cm-bt709-fixed.mp4
 >    Duration: 00:01:00.22, start: 0.000000, bitrate: 1733 kb/s
 >    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1632 kb/s, 23.98 fps, 23.98 tbr, 
19184 tbn, 47.96 tbc (default)
 >    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
 >

Still haven't found a way to fix this without transcoding. Ugh.

Still seems like a bug.

-- 
Love Living Well Doing What You Love?
http://DavidFavor.com/books can help!


More information about the ffmpeg-devel mailing list