0

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.

1
  • Just use PyAV. that's the most direct "wrapper" to ffmpeg's library functions. Commented Nov 3, 2024 at 22:44

1 Answer 1

0

Can't help you with python-ffmpeg but you can try my implementation in ffmpegio. You can check out this discussion thread:

https://github.com/python-ffmpegio/python-ffmpegio/discussions/17

Feel free to start a new thread there if you need help.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.