Search code examples
pythonffmpeg

ffmpeg-python outputs black screen when trying to save as mp4


This is my code. I am trying to make a video out of all pictures in the pics2 directory using ffmpeg.

import subprocess

command = 'ffmpeg -framerate 1 -i "pics2/Image%02d.png" -r 1 -vcodec libx264 -s 1280x720 -pix_fmt yuv420p Output.mp4'
p = subprocess.call(command, shell=True)

This saves an Output.mp4 successfully but the video has no frames (It is completely black)

How do I solve this?


Solution

  • Your player does not like 1 fps

    Many players behave similarly.

    You can still provide a low frame rate for the input, but give a more normal frame rate for the output. ffmpeg will simply duplicate the frames. The output video won't look different than your original command, but it will play.

    ffmpeg -framerate 1 -i "pics2/Image%02d.png" -r 10 -vcodec libx264 -s 1280x720 -pix_fmt yuv420p Output.mp4