canvas-sketch
canvas-sketch copied to clipboard
[cli] MP4 utility – loss of color richness
Not sure what's going on but I've noticed a pretty significant loss of colour richness when converting frames into MP4. I'm not sure if this is some limitation of the H264 but it seems like it should be possible to get just as rich colours as with GIF.
For reference:

Would it be possible to have a test case with that picture and the command line used to generate the outputs (or maybe it's already somewhere?) it'd help other people play with the encoder parameters or inspect the original asset colorspace.
After some discussion on Twitter I've landed on the following settings which have a pretty significant improvement in colour richness, and still uploads to Twitter. Have not tested IG but imagine its probably alright there.
ffmpeg -framerate 20 -i tmp/%02d.png -y -an -c:v libx264 -tune animation \
-preset slow -crf 18 -profile:v high -pix_fmt yuvj420p \
-x264opts colormatrix=bt709 output.mp4
Some of the richness is still lost, and generally it produces a "brighter" (higher contrast) result than the original. I've also noticed playing the MP4 in QuickTime will always look faded compared to VLC and Twitter video players.
@dlespiau that is a good idea, if I get some time I'll try to put together a set of images for a test like that.
Small update: The colormatrix options produce different results in QuickTime (Version 10.4 / 928.13), but seem to result in the same Twitter/VLC colors regardless of what option you pick. bt470bg
and YCgCo
seem to be visually the same in these tests, and look the richest in QuickTime compared to the others, so I will use one of those as the default in canvas-sketch-cli.