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
13 changes: 7 additions & 6 deletions av/audio/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Self, final
from typing import Self, final

import numpy as np
import numpy.typing as npt

from av.frame import Frame

Expand All @@ -10,11 +11,11 @@ from .plane import AudioPlane

format_dtypes: dict[str, str]
_SupportedNDarray = (
np.ndarray[Any, np.dtype[np.float64]] # f8
| np.ndarray[Any, np.dtype[np.float32]] # f4
| np.ndarray[Any, np.dtype[np.int32]] # i4
| np.ndarray[Any, np.dtype[np.int16]] # i2
| np.ndarray[Any, np.dtype[np.uint8]] # u1
npt.NDArray[np.float64]
| npt.NDArray[np.float32]
| npt.NDArray[np.int32]
| npt.NDArray[np.int16]
| npt.NDArray[np.uint8]
)

@final
Expand Down
34 changes: 18 additions & 16 deletions av/container/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ from enum import Flag, IntEnum
from fractions import Fraction
from pathlib import Path
from types import TracebackType
from typing import (
Any,
Literal,
Self,
TypedDict,
overload,
type_check_only,
)
from typing import Any, Literal, Protocol, Self, TypedDict, overload, type_check_only

from typing_extensions import disjoint_base

Expand All @@ -23,6 +16,15 @@ from .output import OutputContainer
from .streams import StreamContainer

type _Real = int | float | Fraction | AVRational
type _IOOpen = Callable[[str, int, dict[str, str]], object]

@type_check_only
class _ReadableFile(Protocol):
def read(self, size: int, /) -> bytes: ...

@type_check_only
class _WritableFile(Protocol):
def write(self, data: bytes, /) -> object: ...

class Flags(Flag):
_value_: int
Expand Down Expand Up @@ -91,7 +93,7 @@ class Chapter(TypedDict):
class Container:
name: str
file: Any
io_open: Any
io_open: _IOOpen | None
open_files: Any
format: ContainerFormat
options: dict[str, str]
Expand All @@ -118,14 +120,14 @@ class Container:

@overload
def open(
file: Any,
file: str | Path | _ReadableFile,
mode: Literal["r"],
format: str | None = None,
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,
io_open: Callable[..., Any] | None = None,
io_open: _IOOpen | None = None,
hwaccel: HWAccel | None = None,
) -> InputContainer: ...
@overload
Expand All @@ -137,30 +139,30 @@ def open(
container_options: dict[str, str] | None = None,
buffer_size: int = 32768,
timeout: _Real | None | tuple[_Real | None, _Real | None] = None,
io_open: Callable[..., Any] | None = None,
io_open: _IOOpen | None = None,
hwaccel: HWAccel | None = None,
) -> InputContainer: ...
@overload
def open(
file: Any,
file: str | Path | _WritableFile,
mode: Literal["w"],
format: str | None = None,
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,
io_open: Callable[..., Any] | None = None,
io_open: _IOOpen | None = None,
hwaccel: HWAccel | None = None,
) -> OutputContainer: ...
@overload
def open(
file: Any,
file: str | Path | _ReadableFile | _WritableFile,
mode: Literal["r", "w"] | None = None,
format: str | None = None,
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,
io_open: Callable[..., Any] | None = None,
io_open: _IOOpen | None = None,
hwaccel: HWAccel | None = None,
) -> InputContainer | OutputContainer: ...
15 changes: 9 additions & 6 deletions 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, final, overload
from typing import final, overload

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

from .core import Container
from .streams import _Indices, _StreamSelector

@final
class InputContainer(Container):
Expand All @@ -27,15 +28,15 @@ class InputContainer(Container):
self, video_streams: tuple[VideoStream, ...]
) -> Iterator[Packet[VideoStream]]: ...
@overload
def demux(self, *, video: Any) -> Iterator[Packet[VideoStream]]: ...
def demux(self, *, video: _Indices) -> Iterator[Packet[VideoStream]]: ...
@overload
def demux(self, audio_stream: AudioStream) -> Iterator[Packet[AudioStream]]: ...
@overload
def demux(
self, audio_streams: tuple[AudioStream, ...]
) -> Iterator[Packet[AudioStream]]: ...
@overload
def demux(self, *, audio: Any) -> Iterator[Packet[AudioStream]]: ...
def demux(self, *, audio: _Indices) -> Iterator[Packet[AudioStream]]: ...
@overload
def demux(
self, subtitle_stream: SubtitleStream
Expand All @@ -51,7 +52,7 @@ class InputContainer(Container):
self, data_streams: tuple[DataStream, ...]
) -> Iterator[Packet[DataStream]]: ...
@overload
def demux(self, *, data: Any) -> Iterator[Packet[DataStream]]: ...
def demux(self, *, data: _Indices) -> Iterator[Packet[DataStream]]: ...
@overload
def demux(
self, attachment_stream: AttachmentStream
Expand All @@ -61,7 +62,9 @@ class InputContainer(Container):
self, attachment_streams: tuple[AttachmentStream, ...]
) -> Iterator[Packet[AttachmentStream]]: ...
@overload
def demux(self, *args: Any, **kwargs: Any) -> Iterator[Packet[Stream]]: ...
def demux(
self, *args: _StreamSelector, **kwargs: _Indices
) -> Iterator[Packet[Stream]]: ...
@overload
def decode(self, video: int) -> Iterator[VideoFrame]: ...
@overload
Expand All @@ -76,7 +79,7 @@ class InputContainer(Container):
def decode(self, *args: SubtitleStream) -> Iterator[SubtitleSet]: ...
@overload
def decode(
self, *args: Any, **kwargs: Any
self, *args: _StreamSelector, **kwargs: _Indices
) -> Iterator[VideoFrame | AudioFrame | SubtitleSet]: ...
def seek(
self,
Expand Down
11 changes: 6 additions & 5 deletions av/container/streams.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ from av.stream import AttachmentStream, DataStream, Stream
from av.subtitles.stream import SubtitleStream
from av.video.stream import VideoStream

type _Indices = int | tuple[int, ...] | list[int]
type _StreamSelector = (
int | Stream | tuple[int | Stream, ...] | list[int | Stream] | dict[str, _Indices]
)

@final
class StreamContainer:
video: tuple[VideoStream, ...]
Expand All @@ -21,11 +26,7 @@ class StreamContainer:
def __getitem__(self, index: int, /) -> Stream: ...
@overload
def __getitem__(self, index: slice, /) -> list[Stream]: ...
def get(
self,
*args: int | Stream | dict[str, int | tuple[int, ...]],
**kwargs: int | tuple[int, ...],
) -> list[Stream]: ...
def get(self, *args: _StreamSelector, **kwargs: _Indices) -> list[Stream]: ...
def best(
self,
type: Literal["video", "audio", "subtitle", "data", "attachment"],
Expand Down
6 changes: 1 addition & 5 deletions av/device.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ class DeviceInfo:
media_types: list[str]

def __init__(
self,
name: str,
description: str,
is_default: bool,
media_types: list[str],
self, name: str, description: str, is_default: bool, media_types: list[str]
) -> None: ...
def __repr__(self) -> str: ...

Expand Down
5 changes: 1 addition & 4 deletions av/dictionary.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ class Dictionary:
def copy(self) -> Dictionary: ...
def pop(self, key: str) -> str: ...
def update(
self,
other: Mapping[str, str] | Iterable[tuple[str, str]] = (),
/,
**kwds: str,
self, other: Mapping[str, str] | Iterable[tuple[str, str]] = (), /, **kwds: str
) -> None: ...
4 changes: 2 additions & 2 deletions av/filter/graph.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fractions import Fraction
from typing import Any, Self, final
from typing import Self, final

from av.audio.format import AudioFormat
from av.audio.frame import AudioFrame
Expand All @@ -25,7 +25,7 @@ class Graph:
def configure(self, auto_buffer: bool = True, force: bool = False) -> None: ...
def link_nodes(self, *nodes: FilterContext) -> Graph: ...
def add(
self, filter: str | Filter, args: Any = None, **kwargs: str
self, filter: str | Filter, args: str | None = None, **kwargs: str
) -> FilterContext: ...
def add_buffer(
self,
Expand Down
43 changes: 33 additions & 10 deletions av/rational.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from decimal import Decimal
from fractions import Fraction
from numbers import Rational
from typing import Any, final, overload
from typing import final, overload

_Comparable = AVRational | Rational | Decimal | float

@final
class AVRational:
Expand All @@ -14,28 +17,48 @@ class AVRational:
def __bool__(self) -> bool: ...
def __float__(self) -> float: ...
def __hash__(self) -> int: ...
def __eq__(self, other: Any, /) -> bool: ...
def __lt__(self, other: Any, /) -> bool: ...
def __le__(self, other: Any, /) -> bool: ...
def __gt__(self, other: Any, /) -> bool: ...
def __ge__(self, other: Any, /) -> bool: ...
def __eq__(self, other: object, /) -> bool: ...
def __lt__(self, other: _Comparable, /) -> bool: ...
def __le__(self, other: _Comparable, /) -> bool: ...
def __gt__(self, other: _Comparable, /) -> bool: ...
def __ge__(self, other: _Comparable, /) -> bool: ...
def __neg__(self) -> AVRational: ...
def __mul__(self, other: Any, /) -> AVRational | Fraction | float: ...
@overload
def __mul__(self, other: AVRational, /) -> AVRational: ...
@overload
def __mul__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __mul__(self, other: float, /) -> float: ...
@overload
def __rmul__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __rmul__(self, other: float, /) -> float: ...
def __truediv__(self, other: Any, /) -> AVRational | Fraction | float: ...
@overload
def __truediv__(self, other: AVRational, /) -> AVRational: ...
@overload
def __truediv__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __truediv__(self, other: float, /) -> float: ...
@overload
def __rtruediv__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __rtruediv__(self, other: float, /) -> float: ...
def __add__(self, other: Any, /) -> AVRational | Fraction | float: ...
@overload
def __add__(self, other: AVRational, /) -> AVRational: ...
@overload
def __add__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __add__(self, other: float, /) -> float: ...
@overload
def __radd__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __radd__(self, other: float, /) -> float: ...
def __sub__(self, other: Any, /) -> AVRational | Fraction | float: ...
@overload
def __sub__(self, other: AVRational, /) -> AVRational: ...
@overload
def __sub__(self, other: int | Fraction, /) -> Fraction: ...
@overload
def __sub__(self, other: float, /) -> float: ...
@overload
def __rsub__(self, other: int | Fraction, /) -> Fraction: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions av/sidedata/encparams.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import IntEnum
from typing import Any, Self, final
from typing import Self, final

import numpy as np

Expand All @@ -20,7 +20,7 @@ class VideoEncParams(SideData):
qp: int
delta_qp: int
def block_params(self, idx: int) -> VideoBlockParams: ...
def qp_map(self) -> np.ndarray[Any, Any]: ...
def qp_map(self) -> np.ndarray[tuple[int, int], np.dtype[np.int32]]: ...

@final
class VideoBlockParams:
Expand Down
5 changes: 3 additions & 2 deletions av/sidedata/motionvectors.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections.abc import Iterator
from typing import Any, Self, final
from typing import Self, final

import numpy as np
import numpy.typing as npt

from av.frame import Frame

Expand All @@ -13,7 +14,7 @@ class MotionVectors(SideData):
def __getitem__(self, index: int, /) -> MotionVector: ...
def __iter__(self) -> Iterator[MotionVector]: ...
def __len__(self) -> int: ...
def to_ndarray(self) -> np.ndarray[Any, Any]: ...
def to_ndarray(self) -> npt.NDArray[np.void]: ...

@final
class MotionVector:
Expand Down
6 changes: 1 addition & 5 deletions av/subtitles/subtitle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class SubtitleSet:

@staticmethod
def create(
text: bytes,
start: int,
end: int,
pts: int = 0,
subtitle_format: int = 1,
text: bytes, start: int, end: int, pts: int = 0, subtitle_format: int = 1
) -> SubtitleSet: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[AssSubtitle | BitmapSubtitle]: ...
Expand Down
Loading
Loading