Saya
Saya

Reputation: 302

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?

Upvotes: 1

Views: 1815

Answers (3)

Akshay Chouhan
Akshay Chouhan

Reputation: 335

can scale the video using -vf scale=500:-2 this fixed black video issue for me

Upvotes: 0

llogan
llogan

Reputation: 133743

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

Upvotes: 1

nickh
nickh

Reputation: 299

The problem with your original script occurs when setting both -framerate and -r. Here is more information about it. Try using this as your command:

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

Brief explanation (based on Saaru Lindestøkke's answer):

ffmpeg               <- call ffmpeg
    -framerate 1     <- set the input framerate to 1
    -i 'pics2/Image%02d.png' <- read PNG images with filename Image01, Image02, etc...
    -vcodec libx264  <- Set the codec to libx264
    -s 1280x720      <- Set the resolution to 1280x720
    -pix_fmt yuv420p <- Set the pixel format to planar YUV 4:2:0, 12bpp
    Output.mp4       <- the output filename

Upvotes: 1

Related Questions