I have a mov file with multiple video streams, and I'm trying to use ffmpeg python bindings to read each stream and save all of its frames.
To do so, I've made a code similar to this one:
import numpy as np
from PIL import Image
import ffmpeg
# Explore streams using probe
probe = ffmpeg.probe(file)
video_streams = [stream for stream in probe['streams'] if stream['codec_type'] == 'video']
for stream in video_streams:
out, _ = (
ffmpeg
.input(file,stream_index=int(stream["index"]))
.output('pipe:', format='rawvideo', pix_fmt='rgb24')
.run(capture_stdout=True)
)
video = (
np
.frombuffer(out, np.uint8)
.reshape([-1, height, width, 3])
)
stream_dir = video_streams_dir / int(stream["index"])
stream_dir.mkdir(exist_ok=True)
for i in range(video.shape[0]):
Image.fromarray(video[i,...]).save(stream_dir / f"{video_name}__{i:04d}.jpeg")
However stream_index=int(stream["index"]) appears to be an invalid parameter, so my question is, how do I specify the input stream for the input node?
Note: It works without that parameter with the first (I believe) video stream.
Update: Found this thread and it appears that ffmpeg does allow it, still haven't tried implementing my own solution based on it.