jonghwanhyeon / python-ffmpeg

A python binding for FFmpeg which provides sync and async APIs
MIT License
302 stars 53 forks source link

Add frames on the fly? #47

Open david-zwicker opened 8 months ago

david-zwicker commented 8 months ago

I'm running a complicated numerical simulation and would like to send frames calculated for a movie to ffmpeg on the fly, e.g., during the calculation. Storing all the data and processing later is impractical since the data would be too large. Is it possible to use the ffmpeg package to achieve this?

In pseudo-code, I want to do something like this:

from ffmpeg import FFmpeg

ffmpeg = (
       FFmpeg()
        .option("y")
        .input("pipe:0")
        .output("output.mp4")
    )

ffmpeg.execute()  # Is this necessary in this case?

for i in range(...):
    # this would be a much more complicated simulation that would calculate a frame
    frame = ... # a NxMx3 array of color values
    ffmpeg.add_frame(frame)

ffmpeg.finalize()  # might be necessary?