My work recently involves programmatically making videos. In python, the typical workflow looks something like this:
import subprocess, Image, ImageDraw
for i in range(frames_per_second * video_duration_seconds):
img = createFrame(i)
img.save("%07d.png" % i)
subprocess.call(["ffmpeg","-y","-r",str(frames_per_second),"-i", "%07d.png","-vcodec","mpeg4", "-qscale","5", "-r", str(frames_per_second), "video.avi"])
This workflow creates an image for each frame in the video and saves it to disk. After all images have been saved, ffmpeg is called to construct a video from all of the images.
Saving the images to disk (not the creation of the images in memory) consumes the majority of the cycles here, and does not appear to be necessary. Is there some way to perform the same function, but without saving the images to disk? So, ffmpeg would be called and the images would be constructed and fed to ffmpeg immediately after being constructed.
ffmpeg -f image2pipe -c:v png -r 30000/1001 -i -
. – TamqrahcreateFrame(i)
returns a Python Image Library image object, which we store inimg
. I think your response is a step in the right direction, but half the challenge would be piping the constructed images to ffmpeg while in the python program. – Gratia