I wrote a little Python program to grab a bunch of PNGs and render them into a movie using the FFmpeg command line. The PNGs are read into [X*Y*3] numpy arrays (ignoring the alpha channel), new frames are added via interpolation, and the data is fed into FFmpeg as a pipe and saved as an mp4.
The files play fine in VLC on Windows, but don't work in iMovie on a Mac. I think it might have to do with most programs expecting H264 videos to be in the YUV420P color space, which my movies aren't. I've tried changing the ffmpeg command -pix_fmt
from rgb24
to yuv420p
, but no go.
Relevant Python code attached below.
def init_vars(args):
global log_file, file_names, command, num_int_frames, num_files, silent
file_names = glob('./*.png')
num_files = len(file_names)
if args.log:
log_file = 'bmmp.log'
else:
log_file = os.devnull
silent = args.silent
frames_per_second = args.fps
wanted_movie_length = args.length
movie_file_name = args.name + '.mp4'
num_int_frames = round((frames_per_second * wanted_movie_length - 1) / (num_files - 1) - 1)
if sys.platform == 'win32':
ffmpeg_bin = 'ffmpeg.exe'
else:
ffmpeg_bin = 'ffmpeg'
command = [ffmpeg_bin,
'-y', # (optional) overwrite output file if it exists
'-f', 'rawvideo',
'-vcodec','rawvideo',
'-s', '1280x720', # size of one frame
'-pix_fmt', 'rgb24',
'-r', str(frames_per_second), # frames per second
'-i', '-', # The input comes from a pipe
'-an', # Tells FFMPEG not to expect any audio
movie_file_name]
Cheers, Eilam
ffmpeg
question. Nevertheless, what is the reason for not usingYUV
colorspace for the videos, this is after all what the H.264 is tuned for – Antti Haapala