Why does a stream have multiple videos?
Requirement: Get a bunch of frames from a video file according to one frame per second. So I wrote the following function
import av
from numpy import ndarray
from loguru import logger
from typing import Generator
video_filename = 'Movies/123.mp4'
def frame_extract_pyav(video_filename: str, is_multi_thread_decode=True) -> Generator[ndarray, None, None]:
with av.open(video_filename, metadata_encoding='utf-8', metadata_errors='ignore') as container:
try:
video = container.streams.video[0]
video.thread_type = "AUTO"
average_fps: int = round(video.average_rate)
for index, frame in enumerate(container.decode(video)):
if index % average_fps == 0:
yield frame.to_rgb().to_ndarray()
except Exception as error:
logger.warning(error)
What I don't understand is why is the type of container.streams
a tuple? Why can a streams
have more than one video
?
Why is it the case that a streams
can have more than one video
? Does it have anything to do with the video encoding format? For example, is it possible for a common mp4 to have one streams
containing multiple video
s?