[FFmpeg-user] ffmpeg MP4/x264 output colours change when input source is different resolution (bug?)

Dan twinbee42 at skytopia.com
Wed Sep 14 12:21:58 EEST 2022


Using the latest 5.1.1 "essentials build" by www.gyan.dev.

Hi all, I'm a beginner to ffmpeg so I'm having a hard time believing that a utility so old and so widely used has such a fundamental bug, but the evidence is staring me in the face and leads me to no other conclusion.

It's incredibly easy to replicate thankfully. I want to convert numerous frames to make an animation, but thankfully, I've simplified the problem to even using a single image to make a '1 frame video' for the purposes of debugging.

Simply perform this command line:

ffmpeg.exe -i original.png -crf 0 -vcodec libx264 output.mp4

...With this "original.png" ("fC2Tj") image: https://i.stack.imgur.com/5jkct.png

And this command line:

ffmpeg.exe -i doubleHeight.png -crf 0 -vcodec libx264 output.mp4

...On this "doubleHeight" ("RGIvA") image: https://i.stack.imgur.com/PLdsb.png

The double height version is darker than it should be. I've checked the resulting video in both Media Player Classic and Chrome.

If you check the dark green colour on the original PNG images, using an eye dropper tool, they're both R=25,G=74,B=15. However, if you check the same colour on the output MP4s, the colour matches on the original PNG, but not the doubleHeight version, which is R=22,G=66,B=12.

If I use -vcodec libx264rgb, instead of -vcodec libx264, that fixes the issue, but I need libx264 so the output video can work on Chrome and other media players.

What gives? CLI output below (for the double height version):

-------------------------------------------------------------------------------

D:\Utils\ffmpeg\bin\ffmpeg.exe -i C:\Users\<USERNAME>\Desktop\testcol\PLdsb.png -crf 0 -vcodec libx264 C:\Users\<USERNAME>\Desktop\testcol\PLdsb.mp4
ffmpeg version 5.1.1-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
   built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
   configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
   libavutil      57. 28.100 / 57. 28.100
   libavcodec     59. 37.100 / 59. 37.100
   libavformat    59. 27.100 / 59. 27.100
   libavdevice    59.  7.100 / 59.  7.100
   libavfilter     8. 44.100 /  8. 44.100
   libswscale      6.  7.100 /  6.  7.100
   libswresample   4.  7.100 /  4.  7.100
   libpostproc    56.  6.100 / 56.  6.100
Input #0, png_pipe, from 'C:\Users\<USERNAME>\Desktop\testcol\PLdsb.png':
   Duration: N/A, bitrate: N/A
   Stream #0:0: Video: png, rgb24(pc), 968x984, 25 fps, 25 tbr, 25 tbn
Stream mapping:
   Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 000001b24acb3400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 000001b24acb3400] profile High 4:4:4 Predictive, level 3.2, 4:4:4, 8-bit
[libx264 @ 000001b24acb3400] 264 - core 164 r3095 baee400 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, mp4, to 'C:\Users\<USERNAME>\Desktop\testcol\PLdsb.mp4':
   Metadata:
     encoder         : Lavf59.27.100
   Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 968x984, q=2-31, 25 fps, 12800 tbn
     Metadata:
       encoder         : Lavc59.37.100 libx264
     Side data:
       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame=    1 fps=0.0 q=0.0 Lsize=       2kB time=00:00:00.00 bitrate=180512.8kbits/s speed=0.0017x
video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 88.235291%
[libx264 @ 000001b24acb3400] frame I:1     Avg QP: 0.00  size:   405
[libx264 @ 000001b24acb3400] mb I  I16..4: 83.5% 16.4%  0.1%
[libx264 @ 000001b24acb3400] 8x8 transform intra:16.4%
[libx264 @ 000001b24acb3400] coded y,u,v intra: 0.0% 0.0% 0.0%
[libx264 @ 000001b24acb3400] i16 v,h,dc,p: 100%  0%  0%  0%
[libx264 @ 000001b24acb3400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41%  0% 59%  0%  0%  0%  0%  0%  0%
[libx264 @ 000001b24acb3400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 38%  6% 56%  0%  0%  0%  0%  0%  0%
[libx264 @ 000001b24acb3400] kb/s:81.00


More information about the ffmpeg-user mailing list