1

I have an animation rendered as a series of png images, and I want to convert it losslessly into an H.264 mp4 video. The images are in the RGB color space.

I tried these options:

ffmpeg -framerate 24 -i "animation.%04d.png" -c:v libx264 -preset veryslow -tune animation -crf 0 "test video.mp4"

But the output file had messed up colors, possibly because of an improper RGB to YUV conversion.

Then I tried these options:

ffmpeg -framerate 24 -i "animation.%04d.png" -c:v libx264rgb -preset veryslow -tune animation -crf 0 "test video.mp4"

The quality of the output video file was the same as that of the original png images, that is the encoding was indeed lossless, but the output file was encoded in the RGB color space, and thus it is not compatible with video editing software (such as Avidemux, I did not test other programs, but I suppose it will be the same).

How do I resolve this?

Is there a way to improve the RGB to YUV conversion, or even to make it lossless?

Or is there a way to improve the compatibility of RGB encoded videos?

and his dog
  • 377
  • 1
  • 5
  • 15
  • 1
    RGB <=> YUV can not be made lossless. – szatmary Feb 18 '19 at 01:46
  • What about nearly lossless? How can I improve the conversion then? – and his dog Feb 18 '19 at 02:05
  • You can try `-pix_fmt yuv444p` to store without chroma subsampling, but that'll still not be lossless (i.e. a non-reversible color transform). – slhck Feb 18 '19 at 16:40
  • @slhck, thank you for the hint. Unfortunately, that does not provide any visible difference in the output video. – and his dog Feb 20 '19 at 01:51
  • 1
    I think h264 is not the right format if you want preserve 100% original image information. There are some RGB codecs out there. I've used e.g. utvideo codec with ffmpeg. Resulting .avi files were more or less compatible with other software, but you'll need to install codecs for better functionality. Otherwise, you can store uncompressed video, but it will take a lot of disk space. – Mikhail V Feb 20 '19 at 05:00
  • @andhisdog - did you figure out the "messed up colors" thing in the end? Like you, `libx264rgb` works, but unfortunately, `libx264` brightens and darkens some colours. Spending hours trying to figure this out. – Twinbee Sep 13 '22 at 11:11

0 Answers0