Based on this older question, I am looking for a good "transfer video codec / compression" for rendering videos from BMPs and/or PNGs and uploading them to Youtube. I am dealing with a lot of entropy / details in my frames.

I built a small Python framework called "bewegung" around ffmpeg and a bunch of Python visualization libraries for animating scientific data. I am calling ffmpeg as follows, writing BMPs directly to stdin:

codec = subprocess.Popen([
    '-y', # force overwrite of output file
    '-framerate', f'{self.fps:d}',
    '-f', 'image2pipe', # force input format
    '-i', '-', # data from stdin
    '-vcodec', 'bmp', # input codec
    '-s:v', f'{self._width:d}x{self._height:d}',
    '-c:v', 'libx264',
    '-preset', 'veryslow',
    '-crf', '0',
    ], stdin = PIPE, stdout = PIPE, stderr = PIPE,)

I originally started with PNGs, but the extra compression/decompression steps simply required too much time. BMPs are faster. The BMPs are using 24 bit RGB.

For content based on a few lines and polygons, this works just fine.

good example

When attempting to visualize content with lots of details, points / dots, for instance (in combination with change of contrast and/or color), I am running into several problems:

bad example

The above example is based on roughly 1M points, aggregated into a density plot. During fade-in, fade-out and changes in density, the quality drops significantly. Ironically, the background is also affected: It should actually be a flat gray tone, but youtube somehow (temporarily) introduces a vertical color gradient with visible steps. While the raw video (before upload) is - as expected - virtually perfect, it comes with its own set of issues: The above example requires 523 MByte of space for 10 seconds at 60 fps 1920x1080 px and barely plays on VLC. Longer videos of this kind are therefore problematic.

I have to admit that I am new to this field: Where do I start reading? How do I optimize the output of ffmpeg for this kind of content for the intended purpose?

  • Try Vimeo. Both sites will always transcode user submissions, the file you upload is not what the viewer is served. But Vimeo applies less compression. You're likely to be disappointed if you expect close to perfect fidelity with fine textures. – Gyan Sep 3 at 8:29
  • @Gyan I know that I can not expect perfection. My problem is more like: I have seen better (on Youtube). So I think that there is still room for improvement ... – s-m-e Sep 3 at 8:43

do i get you wrong about you want a lossless compression?


  1. Choose a CRF value The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so ...



FFV1 is a video codec developed within FFmpeg. It is lossless, meaning that it compresses video without introducing quantization degradations.


you can google lossless compression

| improve this answer | |
  • It does not have to be lossless. I want to "optimize" the kind of compression artifacts that I get on Youtube. I'd like to "force the compression into the right direction", if this makes any sense, by "playing" with the compression of the uploaded video. – s-m-e Sep 4 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.