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

Reino Wijnsma rwijnsma at xs4all.nl
Mon Sep 19 00:49:58 EEST 2022


On 2022-09-14T11:21:58+0200, Dan <twinbee42 at skytopia.com> wrote:
> 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.
Long time ago since I last dealt with this <https://forum.doom9.org/showthread.php?t=170306>. It's all about BT.601 (≤576p) v.s BT.709 (>576p), so for this conversion from RGB to YUV you'll also need a colourmatrix conversion.
I'm no expert, but these are my observations:

ffplay -f lavfi "color=0x194a0f:s=400x576,format=rgb24"       --> R=25,G=74,B=15 (0x194a0f)
ffplay -f lavfi "color=0x194a0f:s=400x576[,format=yuv420p]"   --> R=25,G=74,B=14 (0x194a0e)
ffplay -f lavfi "color=0x194a0f:s=400x576,format=yuv444p"     --> R=25,G=74,B=14 (0x194a0e)

ffplay -f lavfi "color=0x19be0f:s=400x576,format=rgb24"       --> R=25,G=190,B=15 (0x19be0f)
ffplay -f lavfi "color=0x19be0f:s=400x576[,format=yuv420p]"   --> R=25,G=190,B=16 (0x19be10)
ffplay -f lavfi "color=0x19be0f:s=400x576,format=yuv444p"     --> R=25,G=190,B=16 (0x19be10)

I know too little about this for an explanation on why Blue is off by 1.

ffplay -f lavfi "color=0x194a0f:s=400x578,format=rgb24"                                    --> R=25,G=74,B=15 (0x194a0f)
ffplay -f lavfi "color=0x194a0f:s=400x578[,format=yuv420p]"                                --> R=22,G=65,B=12 (0x16410c)
ffplay -f lavfi "color=0x194a0f:s=400x578,format=yuv444p"                                  --> R=22,G=65,B=12 (0x16410c)
ffplay -f lavfi "color=0x194a0f:s=400x578[,format=yuv420p],scale=out_color_matrix=bt709"   --> R=23,G=72,B=11 (0x17480b)
ffplay -f lavfi "color=0x194a0f:s=400x578,format=yuv444p,scale=out_color_matrix=bt709"     --> R=25,G=74,B=15 (0x194a0f)

ffplay -f lavfi "color=0x19be0f:s=400x578,format=rgb24"                                    --> R=25,G=190,B=15 (0x19be0f)
ffplay -f lavfi "color=0x19be0f:s=400x578[,format=yuv420p]"                                --> R=14,G=164,B=11 (0x0ea40b)
ffplay -f lavfi "color=0x19be0f:s=400x578,format=yuv444p"                                  --> R=14,G=164,B=11 (0x0ea40b)
ffplay -f lavfi "color=0x19be0f:s=400x578[,format=yuv420p],scale=out_color_matrix=bt709"   --> R=23,G=189,B=14 (0x17bd0e)
ffplay -f lavfi "color=0x19be0f:s=400x578,format=yuv444p,scale=out_color_matrix=bt709"     --> R=26,G=189,B=15 (0x1abd0f)

It's not exactly the same colour, but it's the closest you'll get.
I've also tried zscale, but with ffplay it fails with the following error-message:

ffplay -f lavfi "color=0x194a0f:s=400x578,format=yuv444p,zscale=m=709"
[Parsed_zscale_2 @ 0359d6c0] code 3074: no path between colorspaces

With FFmpeg, creating a temp-file, zscale does work:

ffmpeg -i PLdsb.png -t 5 -vf "zscale=m=709" -c:v libx264 -crf 0 PLdsb_zscale-bt709.mp4
ffplay PLdsb_zscale-bt709.mp4   --> R=24,G=74,B=14 (0x184a0e) | R=25,G=190,B=14 (0x19be0e)

Again, not exactly the same colour, but very close.

On 2022-09-15T13:07:08+0200, Michael Koch <astroelectronic at t-online.de> wrote:
> Please try this, for me it works with VLC player, the color is exactly the same:
>
> ffmpeg -f lavfi -i color=0x19be0f:s=400x576 -colorspace bt709 -color_primaries bt709 -color_trc bt709 -crf 0 -vcodec libx264 -t 5 -y out1.mp4
> ffmpeg -f lavfi -i color=0x19be0f:s=400x720 -colorspace bt709 -color_primaries bt709 -color_trc bt709 -crf 0 -vcodec libx264 -t 5 -y out2.mp4
These are all VUI (Video Usability Information) options and, unlike the colourmatrix conversions above, don't have a direct impact on the video-image itself.
It's kind of like meta-data. Your media player needs to support it to display the correct colours. MediaInfo can show you this, like for instance:

Color range                    : Full
Matrix coefficients            : BT.709

ffmpeg -i PLdsb.png -t 5 -color_range tv -colorspace bt470bg -c:v libx264 -crf 0 PLdsb_vui-tv601.mp4
ffplay PLdsb_vui-tv601.mp4   --> R=22,G=65,B=12 (0x16410c) | R=14,G=164,B=11 (0x0ea40b)
mpc-hc PLdsb_vui-tv601.mp4   --> R=25,G=74,B=14 (0x194a0e) | R=25,G=190,B=16 (0x19be10)

If you insist on using these VUI options, then in contrast to what you might expect (PC,BT.709) it's actually TV,BT.601 that has the expected result.
Welcome to the wonderful world of video conversions.

On 2022-09-15T11:40:10+0200, Paul B Mahol <onemda at gmail.com> wrote:
> Looks like your knowledge is very limited, incorrect and completely full of nonsense. 
On 2022-09-16T15:38:51+0200, Paul B Mahol <onemda at gmail.com> wrote:
> It is evident that your knowledge is exactly 0. 
On 2022-09-14T17:01:39+0200, Paul B Mahol <onemda at gmail.com> wrote:
> Next time be more constructive and try it before pointlesly commenting here in so bold and arrogant fashion. 
Do you have any idea how rude and condescending your posts are? Disgraceful! Especially for an FFmpeg-developer.
Next time please refrain from posting unless you have actually something useful and helpful to add!

-- 
Reino



More information about the ffmpeg-user mailing list