Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions av/container/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ from enum import Flag, IntEnum
from fractions import Fraction
from pathlib import Path
from types import TracebackType
from typing import Any, ClassVar, Literal, Self, TypedDict, cast, overload
from typing import (
Any,
ClassVar,
Literal,
Self,
TypedDict,
cast,
overload,
type_check_only,
)

from typing_extensions import disjoint_base

from av.codec.hwaccel import HWAccel
from av.format import ContainerFormat
Expand All @@ -13,7 +24,7 @@ from .input import InputContainer
from .output import OutputContainer
from .streams import StreamContainer

Real = int | float | Fraction | AVRational
type _Real = int | float | Fraction | AVRational

class Flags(Flag):
gen_pts = cast(ClassVar[Flags], ...)
Expand Down Expand Up @@ -69,13 +80,15 @@ class AudioCodec(IntEnum):
pcm_u8 = cast(int, ...)
pcm_vidc = cast(int, ...)

@type_check_only
class Chapter(TypedDict):
id: int
start: int
end: int
time_base: AVRational
metadata: dict[str, str]

@disjoint_base
class Container:
name: str
file: Any
Expand All @@ -87,8 +100,8 @@ class Container:
container_options: dict[str, str]
streams: StreamContainer
metadata: dict[str, str]
open_timeout: Real | None
read_timeout: Real | None
open_timeout: _Real | None
read_timeout: _Real | None
flags: int
video_codec_id: int
def dumps_format(self) -> str: ...
Expand All @@ -113,7 +126,7 @@ def open(
options: dict[str, str] | None = None,
container_options: dict[str, str] | None = None,
buffer_size: int = 32768,
timeout: Real | None | tuple[Real | None, Real | None] = None,
timeout: _Real | None | tuple[_Real | None, _Real | None] = None,
io_open: Callable[..., Any] | None = None,
hwaccel: HWAccel | None = None,
) -> InputContainer: ...
Expand All @@ -125,7 +138,7 @@ def open(
options: dict[str, str] | None = None,
container_options: dict[str, str] | None = None,
buffer_size: int = 32768,
timeout: Real | None | tuple[Real | None, Real | None] = None,
timeout: _Real | None | tuple[_Real | None, _Real | None] = None,
io_open: Callable[..., Any] | None = None,
hwaccel: HWAccel | None = None,
) -> InputContainer: ...
Expand All @@ -137,7 +150,7 @@ def open(
options: dict[str, str] | None = None,
container_options: dict[str, str] | None = None,
buffer_size: int = 32768,
timeout: Real | None | tuple[Real | None, Real | None] = None,
timeout: _Real | None | tuple[_Real | None, _Real | None] = None,
io_open: Callable[..., Any] | None = None,
hwaccel: HWAccel | None = None,
) -> OutputContainer: ...
Expand All @@ -149,7 +162,7 @@ def open(
options: dict[str, str] | None = None,
container_options: dict[str, str] | None = None,
buffer_size: int = 32768,
timeout: Real | None | tuple[Real | None, Real | None] = None,
timeout: _Real | None | tuple[_Real | None, _Real | None] = None,
io_open: Callable[..., Any] | None = None,
hwaccel: HWAccel | None = None,
) -> InputContainer | OutputContainer: ...
3 changes: 2 additions & 1 deletion av/container/input.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterator
from typing import Any, overload
from typing import Any, final, overload

from av.audio.frame import AudioFrame
from av.audio.stream import AudioStream
Expand All @@ -12,6 +12,7 @@ from av.video.stream import VideoStream

from .core import Container

@final
class InputContainer(Container):
start_time: int
start_time_realtime: int | None
Expand Down
11 changes: 5 additions & 6 deletions av/container/output.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Sequence
from fractions import Fraction
from typing import TypeVar, overload
from typing import final, overload

from av.audio import _AudioCodecName
from av.audio.stream import AudioStream
Expand All @@ -15,8 +15,7 @@ from av.video.stream import VideoStream

from .core import Container

_StreamT = TypeVar("_StreamT", bound=Stream)

@final
class OutputContainer(Container):
@overload
def add_stream(
Expand Down Expand Up @@ -58,9 +57,9 @@ class OutputContainer(Container):
rate: AVRational | Fraction | int | None = None,
**kwargs,
) -> Stream: ...
def add_stream_from_template(
self, template: _StreamT, opaque: bool | None = None, **kwargs
) -> _StreamT: ...
def add_stream_from_template[StreamT: Stream](
self, template: StreamT, opaque: bool | None = None, **kwargs
) -> StreamT: ...
def add_attachment(
self, name: str, mimetype: str, data: bytes
) -> AttachmentStream: ...
Expand Down
9 changes: 4 additions & 5 deletions av/container/streams.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from collections.abc import Iterator
from typing import Literal, overload
from typing import Literal, final, overload

from av.audio.stream import AudioStream
from av.stream import AttachmentStream, DataStream, Stream
from av.subtitles.stream import SubtitleStream
from av.video.stream import VideoStream

@final
class StreamContainer:
video: tuple[VideoStream, ...]
audio: tuple[AudioStream, ...]
Expand All @@ -17,11 +18,9 @@ class StreamContainer:
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[Stream]: ...
@overload
def __getitem__(self, index: int) -> Stream: ...
def __getitem__(self, index: int, /) -> Stream: ...
@overload
def __getitem__(self, index: slice) -> list[Stream]: ...
@overload
def __getitem__(self, index: int | slice) -> Stream | list[Stream]: ...
def __getitem__(self, index: slice, /) -> list[Stream]: ...
def get(
self,
*args: int | Stream | dict[str, int | tuple[int, ...]],
Expand Down