Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PyAV
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 37
    • Issues 37
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 26
    • Merge requests 26
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyAV
  • PyAV
  • Issues
  • #1085
Closed
Open
Issue created Feb 08, 2023 by ponponon@ponponon

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 videos?

Assignee
Assign to
Time tracking