Skip to content

Commit

Permalink
Sync with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Mar 5, 2024
1 parent 4580128 commit 716628e
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 164 deletions.
3 changes: 0 additions & 3 deletions av/audio/codeccontext.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from typing import Literal

from av.codec.context import CodecContext
from av.frame import Frame
from av.packet import Packet

from .format import AudioFormat
from .frame import AudioFrame
from .layout import AudioLayout

class AudioCodecContext(CodecContext):
Expand Down
6 changes: 2 additions & 4 deletions av/audio/format.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import Any

class AudioFormat:
name: str
bytes: int
bits: int
is_planar: bool
is_packed: bool
planar: Any
packed: Any
planar: AudioFormat
packed: AudioFormat
container_name: str
17 changes: 14 additions & 3 deletions av/audio/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from typing import Any, Union

import numpy as np

from av.frame import Frame

from .plane import AudioPlane

format_dtypes: dict[str, str]
_SupportedNDarray = Union[
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
]

class AudioFrame(Frame):
planes: tuple[AudioPlane, ...]
Expand All @@ -16,9 +27,9 @@ class AudioFrame(Frame):
layout: str = "stereo",
samples: int = 0,
align: int = 1,
): ...
def to_ndarray(self): ...
) -> None: ...
@staticmethod
def from_ndarray(
array, format: str = "s16", layout: str = "stereo"
array: _SupportedNDarray, format: str = "s16", layout: str = "stereo"
) -> AudioFrame: ...
def to_ndarray(self) -> _SupportedNDarray: ...
5 changes: 3 additions & 2 deletions av/audio/layout.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
channel_descriptions: dict[str, str]

class AudioLayout:
name: str
layout: int
nb_channels: int
channels: tuple[AudioChannels]
channels: tuple[AudioChannel, ...]

class AudioChannels:
class AudioChannel:
name: str
description: str
4 changes: 3 additions & 1 deletion av/audio/plane.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class AudioPlane:
from av.plane import Plane

class AudioPlane(Plane):
buffer_size: int
13 changes: 8 additions & 5 deletions av/audio/resampler.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from av.filter.graph import Graph

from .format import AudioFormat
from .frame import AudioFrame
from .layout import AudioLayout

class AudioResampler:
rate: int
frame_size: int
format: AudioFormat
graph: None
graph: Graph | None

def __init__(
self,
format=None,
layout=None,
format: AudioFormat | None = None,
layout: AudioLayout | None = None,
rate: int | None = None,
frame_size: int | None = None,
): ...
def resample(self, frame: AudioFrame | None) -> list: ...
) -> None: ...
def resample(self, frame: AudioFrame | None) -> list[AudioFrame]: ...
15 changes: 14 additions & 1 deletion av/audio/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
from typing import Literal

from av.packet import Packet
from av.stream import Stream

class AudioStream(Stream): ...
from .codeccontext import AudioCodecContext
from .format import AudioFormat
from .frame import AudioFrame

class AudioStream(Stream):
type: Literal["audio"]
format: AudioFormat
codec_context: AudioCodecContext

def encode(self, frame: AudioFrame | None = None) -> list[Packet]: ... # type: ignore[override]
def decode(self, packet: Packet | None = None) -> list[AudioFrame]: ...
46 changes: 35 additions & 11 deletions av/container/core.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
from numbers import Real
from pathlib import Path
from typing import Any, Iterator, Literal, overload
from types import TracebackType
from typing import Any, Callable, Literal, Type, overload

from av.enum import EnumFlag

from .input import InputContainer
from .output import OutputContainer
from .streams import StreamContainer

class Flags(EnumFlag):
GENPTS: int
IGNIDX: int
NONBLOCK: int
IGNDTS: int
NOFILLIN: int
NOPARSE: int
NOBUFFER: int
CUSTOM_IO: int
DISCARD_CORRUPT: int
FLUSH_PACKETS: int
BITEXACT: int
SORT_DTS: int
FAST_SEEK: int
SHORTEST: int
AUTO_BSF: int

class Container:
writeable: bool
name: str
Expand All @@ -21,13 +41,17 @@ class Container:
container_options: dict[str, str]
stream_options: list[str]
streams: StreamContainer
duration: int | None
metadata: dict[str, str]
open_timeout: Real | None
read_timeout: Real | None

def __enter__(self) -> Container: ...
def __exit__(self, exc_type, exc_val, exc_tb): ...
def __exit__(
self,
exc_type: Type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> bool: ...
def err_check(self, value: int) -> int: ...
def set_timeout(self, timeout: Real | None) -> None: ...
def start_timeout(self) -> None: ...
Expand All @@ -43,8 +67,8 @@ def open(
metadata_encoding: str = "utf-8",
metadata_errors: str = "strict",
buffer_size: int = 32768,
timeout=Real | None | tuple[Real | None, Real | None],
io_open=None,
timeout: Real | None | tuple[Real | None, Real | None] = None,
io_open: Callable[..., Any] | None = None,
) -> InputContainer: ...
@overload
def open(
Expand All @@ -57,8 +81,8 @@ def open(
metadata_encoding: str = "utf-8",
metadata_errors: str = "strict",
buffer_size: int = 32768,
timeout=Real | None | tuple[Real | None, Real | None],
io_open=None,
timeout: Real | None | tuple[Real | None, Real | None] = None,
io_open: Callable[..., Any] | None = None,
) -> InputContainer: ...
@overload
def open(
Expand All @@ -71,8 +95,8 @@ def open(
metadata_encoding: str = "utf-8",
metadata_errors: str = "strict",
buffer_size: int = 32768,
timeout=Real | None | tuple[Real | None, Real | None],
io_open=None,
timeout: Real | None | tuple[Real | None, Real | None] = None,
io_open: Callable[..., Any] | None = None,
) -> OutputContainer: ...
@overload
def open(
Expand All @@ -85,6 +109,6 @@ def open(
metadata_encoding: str = "utf-8",
metadata_errors: str = "strict",
buffer_size: int = 32768,
timeout=Real | None | tuple[Real | None, Real | None],
io_open=None,
timeout: Real | None | tuple[Real | None, Real | None] = None,
io_open: Callable[..., Any] | None = None,
) -> InputContainer | OutputContainer: ...
11 changes: 7 additions & 4 deletions av/container/input.pyi
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
from typing import Iterator, Literal, overload
from typing import Any, Iterator, Literal, overload

from av.audio.frame import AudioFrame
from av.audio.stream import AudioStream
from av.packet import Packet
from av.stream import Stream
from av.subtitles.stream import SubtitleStream
from av.subtitles.subtitle import SubtitleSet
from av.video.frame import VideoFrame
from av.video.stream import VideoStream

from .core import Container
from .streams import Stream

class InputContainer(Container):
start_time: int
duration: int | None
bit_rate: int
size: int

def __enter__(self) -> InputContainer: ...
def close(self) -> None: ...
def demux(self, *args, **kwargs) -> Iterator[Packet]: ...
def demux(self, *args: Any, **kwargs: Any) -> Iterator[Packet]: ...
@overload
def decode(self, *args: VideoStream) -> Iterator[VideoFrame]: ...
@overload
Expand All @@ -26,7 +28,7 @@ class InputContainer(Container):
def decode(self, *args: SubtitleStream) -> Iterator[SubtitleSet]: ...
@overload
def decode(
self, *args, **kwargs
self, *args: Any, **kwargs: Any
) -> Iterator[VideoFrame | AudioFrame | SubtitleSet]: ...
def seek(
self,
Expand All @@ -39,3 +41,4 @@ class InputContainer(Container):
unsupported_frame_offset: bool = False,
unsupported_byte_offset: bool = False,
) -> None: ...
def flush_buffers(self) -> None: ...
16 changes: 16 additions & 0 deletions av/container/output.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
from fractions import Fraction
from typing import Sequence

from av.packet import Packet
from av.stream import Stream

from .core import Container

class OutputContainer(Container):
def __enter__(self) -> OutputContainer: ...
def add_stream(
self,
codec_name: str | None = None,
rate: Fraction | int | float | None = None,
template: Stream | None = None,
options: dict[str, str] | None = None,
) -> Stream: ...
def start_encoding(self) -> None: ...
def close(self) -> None: ...
def mux(self, packets: Sequence[Packet]) -> None: ...
def mux_one(self, packet: Packet) -> None: ...
69 changes: 8 additions & 61 deletions av/container/streams.pyi
Original file line number Diff line number Diff line change
@@ -1,69 +1,16 @@
from fractions import Fraction
from typing import Iterator, Literal, overload
from typing import Iterator, overload

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

class Codec:
name: str
mode: Literal["r", "w"]

frame_rates: list[Fraction] | None
audio_rates: list[int] | None

class CodecContext:
name: str
bit_rate: int | None
width: int
height: int
pix_fmt: str | None
sample_aspect_ratio: Fraction | None
sample_rate: int | None
channels: int
extradata_size: int
is_open: Literal[0, 1]
is_encoder: Literal[0, 1]
is_decoder: Literal[0, 1]

class Stream:
thread_type: Literal["NONE", "FRAME", "SLICE", "AUTO"]

id: int
profile: str | None
codec_context: CodecContext

index: int
time_base: Fraction | None
average_rate: Fraction | None
base_rate: Fraction | None
guessed_rate: Fraction | None

start_time: int | None
duration: int | None
frames: int
language: str | None

# Defined by `av_get_media_type_string` at
# https://ffmpeg.org/doxygen/6.0/libavutil_2utils_8c_source.html
type: Literal["video", "audio", "data", "subtitle", "attachment"]

# From `codec_context`
name: str
bit_rate: int | None
sample_rate: int | None
channels: int
extradata_size: int
is_open: Literal[0, 1]
is_encoder: Literal[0, 1]
is_decoder: Literal[0, 1]

def decode(self, packet=None): ...
def encode(self, frame=None): ...

class StreamContainer:
video: tuple[VideoStream, ...]
audio: tuple[Stream, ...]
subtitles: tuple[Stream, ...]
data: tuple[Stream, ...]
audio: tuple[AudioStream, ...]
subtitles: tuple[SubtitleStream, ...]
data: tuple[DataStream, ...]
other: tuple[Stream, ...]

def __init__(self) -> None: ...
Expand Down
Loading

0 comments on commit 716628e

Please sign in to comment.