ffmpeg-python
ffmpeg-python copied to clipboard
Lack of information on how to use input pipes
I'm trying to make video from image and audio numpy arrays instead of reading them from file, and there's not enough information on how to do that.
I only managed to save images as video, but I also need to somehow write audio, and I can't find a way to have multiple pipes.
output_file = "output.mp4"
# video stream
video = (
ffmpeg
.input("pipe:", format="rawvideo", pix_fmt="bgr24", s="{}x{}".format(*video_res), r=video_frame_rate)
.output(output_file, pix_fmt="yuv420p", vcodec="libx264", r=video_frame_rate)
.overwrite_output()
.run_async(pipe_stdin=True)
)
# write video frames to video input pipe
for image, duration in zip(images, images_durations):
for _ in range(duration):
video.stdin.write(image.tobytes())
You can't pass multiple pipes to a process. Even if you could, for some reason ffmpeg probably wouldn't be compatible with it as it doesn't even allow reading from 2 named pipes. The cleanest way is to have 2 processes: one to an audio file, one to a video file. Then at the end of the script, combine them.