2

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?

6
  • 1
    RGB <=> YUV can not be made lossless.
    – szatmary
    Feb 18, 2019 at 1:46
  • What about nearly lossless? How can I improve the conversion then? Feb 18, 2019 at 2: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, 2019 at 16:40
  • @slhck, thank you for the hint. Unfortunately, that does not provide any visible difference in the output video. Feb 20, 2019 at 1: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, 2019 at 5:00

0

You must log in to answer this question.

Browse other questions tagged .