cutcutcodec.core.io.scheduler.scheduler

cutcutcodec.core.io.scheduler.scheduler(streams: list[Stream], rates: list[Fraction | int], start_time: Fraction = Fraction(0, 1), shapes: None | tuple[int, int] | list[None | tuple[int, int]] = None, **kwargs) Iterable[tuple[int, Frame]][source]

Extract in chronological order the frames of all flows.

Gives up frames until all streams have raised the OutOfTimeRange exception.

Parameters

streamslist[cutcutcodec.core.classes.stream.Stream]

Audio or video streams to exract the frames.

rateslist[Fraction]

The frame rate for video streams and the sample rate for audio streams.

start_timeFraction, default=0

The position of the first frame yielded. The frame before are ignored.

shapestuple[int, int] or list[tuple[int, int]], optional

For video only, ignore if there is no video stream. Each shape are transmitted to the stream. If the list is not provided, the same shape is transmitted to all video streams.

**kwargsdict

Transmitted to the functions cutcutcodec.core.io.scheduler.audio_frames_async and cutcutcodec.core.io.scheduler.video_frames_async.

Yields

indexint

The index of the concerned stream in the order of the provided list.

framecutcutcodec.core.classes.frame.Frame

The future frame of the stream considered. The time attribute is guaranteed to be monotonic.

Raises

cutcutcodec.core.exceptions.MissingStreamError

If no frame are yielded.

Examples

>>> from fractions import Fraction
>>> from cutcutcodec.core.filter.audio.subclip import FilterAudioSubclip
>>> from cutcutcodec.core.filter.video.subclip import FilterVideoSubclip
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
>>> from cutcutcodec.core.generation.video.noise import GeneratorVideoNoise
>>> from cutcutcodec.core.io.scheduler import scheduler
>>>
>>> s_1 = (
...     FilterVideoSubclip(GeneratorVideoNoise(0).out_streams, 0, Fraction(1, 10)).out_streams
... )
>>> s_2 = (
...     FilterVideoSubclip(GeneratorVideoNoise(0).out_streams, 0, Fraction(1, 4)).out_streams
... )
>>> streams_video = [s_1[0], s_2[0]]
>>> rates_video = [Fraction(30), Fraction(24)]
>>> s_3 = (
...     FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 0, Fraction(1, 10)).out_streams
... )
>>> s_4 = (
...     FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 0, Fraction(1, 4)).out_streams
... )
>>> streams_audio = [s_3[0], s_4[0]]
>>> rates_audio = [96000, 48000]
>>>
>>> # test audio only
>>> for index, frame in scheduler(streams_audio, rates_audio):
...     index, frame.time
...
(0, Fraction(0, 1))
(1, Fraction(0, 1))
(0, Fraction(32, 375))
(1, Fraction(32, 375))
(1, Fraction(64, 375))
>>> for index, frame in scheduler(streams_audio, rates_audio, start_time=Fraction(1, 10)):
...     index, frame.time
...
(1, Fraction(1, 10))
(1, Fraction(139, 750))
>>>
>>> # test video only
>>> for index, frame in scheduler(streams_video, rates_video, shape=(1, 1)):
...     index, frame.time
...
(0, Fraction(0, 1))
(1, Fraction(0, 1))
(0, Fraction(1, 30))
(1, Fraction(1, 24))
(0, Fraction(1, 15))
(1, Fraction(1, 12))
(1, Fraction(1, 8))
(1, Fraction(1, 6))
(1, Fraction(5, 24))
>>> for index, frame in scheduler(streams_video, rates_video, Fraction(1, 10), shape=(1, 1)):
...     index, frame.time
...
(1, Fraction(1, 8))
(1, Fraction(1, 6))
(1, Fraction(5, 24))
>>>
>>> # test audio and video
>>> for index, frame in scheduler(
...     streams_audio+streams_video, rates_audio+rates_video, shape=(1, 1), samples=4096
... ):
...     index, frame.time
...
(0, Fraction(0, 1))
(1, Fraction(0, 1))
(2, Fraction(0, 1))
(3, Fraction(0, 1))
(2, Fraction(1, 30))
(3, Fraction(1, 24))
(0, Fraction(16, 375))
(2, Fraction(1, 15))
(3, Fraction(1, 12))
(0, Fraction(32, 375))
(1, Fraction(32, 375))
(3, Fraction(1, 8))
(3, Fraction(1, 6))
(1, Fraction(64, 375))
(3, Fraction(5, 24))
>>>