Skip to content

Commit f43d643

Browse files
committed
Type all FFmpeg encoder names
1 parent dabe2ab commit f43d643

10 files changed

Lines changed: 333 additions & 11 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ v18.1.0 (Unreleased)
3333

3434
Features:
3535

36+
- Infer the specific stream and codec context types for all FFmpeg encoder names in type-checked code by :gh-user:`WyattBlue`.
3637
- Add ``CodecContext.supported_options`` to discover generic and codec-specific options by :gh-user:`WyattBlue` (:issue:`2032`).
3738
- Add ``Packet.rescale_ts()`` to rescale packet PTS, DTS, and duration to a new ``AVRational`` time base by :gh-user:`WyattBlue`.
3839
- Support reusing the thread's current CUDA context via a ``current_ctx`` flag on ``CudaContext`` and ``VideoFrame.from_dlpack``, for interop with libraries like PyTorch that initialize CUDA first by :gh-user:`Yozer` (:pr:`2339`).

av/audio/__init__.pyi

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,120 @@ from typing import Literal
33
from .frame import AudioFrame
44
from .stream import AudioStream
55

6+
# FFmpeg 8.1 encoders and the codec descriptor aliases that resolve to them.
67
_AudioCodecName = Literal[
78
"aac",
9+
"aac_at",
10+
"aac_mf",
11+
"ac3",
12+
"ac3_fixed",
13+
"ac3_mf",
14+
"adpcm_adx",
15+
"adpcm_argo",
16+
"adpcm_g722",
17+
"adpcm_g726",
18+
"adpcm_g726le",
19+
"adpcm_ima_alp",
20+
"adpcm_ima_amv",
21+
"adpcm_ima_apm",
22+
"adpcm_ima_qt",
23+
"adpcm_ima_ssi",
24+
"adpcm_ima_wav",
25+
"adpcm_ima_ws",
26+
"adpcm_ms",
27+
"adpcm_swf",
28+
"adpcm_yamaha",
29+
"alac",
30+
"alac_at",
31+
"amr_nb",
32+
"amr_wb",
33+
"anull",
34+
"aptx",
35+
"aptx_hd",
36+
"codec2",
37+
"comfortnoise",
38+
"dca",
39+
"dfpwm",
40+
"dts",
41+
"eac3",
42+
"flac",
43+
"g722",
44+
"g723_1",
45+
"g726",
46+
"g726le",
47+
"gsm",
48+
"gsm_ms",
49+
"ilbc",
50+
"ilbc_at",
51+
"lc3",
52+
"libcodec2",
53+
"libfdk_aac",
54+
"libgsm",
55+
"libgsm_ms",
56+
"libilbc",
57+
"liblc3",
58+
"libmp3lame",
59+
"libopencore_amrnb",
860
"libopus",
61+
"libshine",
62+
"libspeex",
63+
"libtwolame",
64+
"libvo_amrwbenc",
65+
"libvorbis",
66+
"mlp",
967
"mp2",
68+
"mp2fixed",
1069
"mp3",
70+
"mp3_mf",
71+
"nellymoser",
72+
"opus",
1173
"pcm_alaw",
74+
"pcm_alaw_at",
75+
"pcm_bluray",
76+
"pcm_dvd",
77+
"pcm_f32be",
78+
"pcm_f32le",
79+
"pcm_f64be",
80+
"pcm_f64le",
1281
"pcm_mulaw",
82+
"pcm_mulaw_at",
83+
"pcm_s16be",
84+
"pcm_s16be_planar",
1385
"pcm_s16le",
86+
"pcm_s16le_planar",
87+
"pcm_s24be",
88+
"pcm_s24daud",
89+
"pcm_s24le",
90+
"pcm_s24le_planar",
91+
"pcm_s32be",
92+
"pcm_s32le",
93+
"pcm_s32le_planar",
94+
"pcm_s64be",
95+
"pcm_s64le",
96+
"pcm_s8",
97+
"pcm_s8_planar",
98+
"pcm_u16be",
99+
"pcm_u16le",
100+
"pcm_u24be",
101+
"pcm_u24le",
102+
"pcm_u32be",
103+
"pcm_u32le",
104+
"pcm_u8",
105+
"pcm_vidc",
106+
"ra_144",
107+
"real_144",
108+
"roq_dpcm",
109+
"s302m",
110+
"sbc",
111+
"sonic",
112+
"sonicls",
113+
"speex",
114+
"truehd",
115+
"tta",
116+
"vorbis",
117+
"wavpack",
118+
"wmav1",
119+
"wmav2",
14120
]
15121

16122
__all__ = ("AudioFrame", "AudioStream")

av/codec/context.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ from typing import ClassVar, Literal, cast, overload
66
from av.audio import _AudioCodecName
77
from av.audio.codeccontext import AudioCodecContext
88
from av.packet import Packet
9+
from av.subtitles import _SubtitleCodecName
10+
from av.subtitles.codeccontext import SubtitleCodecContext
911
from av.video import _VideoCodecName
1012
from av.video.codeccontext import VideoCodecContext
1113

@@ -169,6 +171,13 @@ class CodecContext:
169171
) -> VideoCodecContext: ...
170172
@overload
171173
@staticmethod
174+
def create(
175+
codec: _SubtitleCodecName,
176+
mode: Literal["r", "w"] | None = None,
177+
hwaccel: HWAccel | None = None,
178+
) -> SubtitleCodecContext: ...
179+
@overload
180+
@staticmethod
172181
def create(
173182
codec: str | Codec,
174183
mode: Literal["r", "w"] | None = None,

av/container/output.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from av.audio.stream import AudioStream
77
from av.codec.hwaccel import HWAccel
88
from av.packet import Packet
99
from av.stream import AttachmentStream, DataStream, Stream
10+
from av.subtitles import _SubtitleCodecName
1011
from av.subtitles.stream import SubtitleStream
1112
from av.video import _VideoCodecName
1213
from av.video.stream import VideoStream
@@ -34,6 +35,14 @@ class OutputContainer(Container):
3435
**kwargs,
3536
) -> VideoStream: ...
3637
@overload
38+
def add_stream(
39+
self,
40+
codec_name: _SubtitleCodecName,
41+
rate: Fraction | int | None = None,
42+
options: dict[str, str] | None = None,
43+
**kwargs,
44+
) -> SubtitleStream: ...
45+
@overload
3746
def add_stream(
3847
self,
3948
codec_name: str,

av/subtitles/__init__.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Literal
2+
3+
# FFmpeg 8.1 encoders and the codec descriptor aliases that resolve to them.
4+
_SubtitleCodecName = Literal[
5+
"ass",
6+
"dvb_subtitle",
7+
"dvbsub",
8+
"dvd_subtitle",
9+
"dvdsub",
10+
"mov_text",
11+
"srt",
12+
"ssa",
13+
"subrip",
14+
"text",
15+
"ttml",
16+
"webvtt",
17+
"xsub",
18+
]

av/subtitles/stream.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ from av.packet import Packet
22
from av.stream import Stream
33
from av.subtitles.subtitle import AssSubtitle, BitmapSubtitle, SubtitleSet
44

5+
from .codeccontext import SubtitleCodecContext
6+
57
class SubtitleStream(Stream):
8+
codec_context: SubtitleCodecContext
69
def decode(
710
self, packet: Packet | None = None
811
) -> list[AssSubtitle] | list[BitmapSubtitle]: ...

0 commit comments

Comments
 (0)