Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve stub in av.audio #1316

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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]: ...
11 changes: 10 additions & 1 deletion av/audio/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
from av.packet import Packet
from av.stream import Stream

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

class AudioStream(Stream):
format: AudioFormat
type = "audio"
laggykiller marked this conversation as resolved.
Show resolved Hide resolved

def encode(self, frame: AudioFrame | None = None) -> list[Packet]: ...
def decode(self, packet: Packet | None = None) -> list[AudioFrame]: ...
Loading