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([
'ffmpeg',
'-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',
video_fn,
], 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.
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:
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?