Debian Codegraph @

av/codec/codec.pyi

raw
1 from enum import Flag, IntEnum
2 from fractions import Fraction
3 from typing import ClassVar, Literal, Sequence, cast, overload
4
5 from av.audio.codeccontext import AudioCodecContext
6 from av.audio.format import AudioFormat
7 from av.subtitles.codeccontext import SubtitleCodecContext
8 from av.video.codeccontext import VideoCodecContext
9 from av.video.format import VideoFormat
10
11 from .context import CodecContext
12
13 class Properties(Flag):
14 NONE = cast(ClassVar[Properties], ...)
15 INTRA_ONLY = cast(ClassVar[Properties], ...)
16 LOSSY = cast(ClassVar[Properties], ...)
17 LOSSLESS = cast(ClassVar[Properties], ...)
18 REORDER = cast(ClassVar[Properties], ...)
19 BITMAP_SUB = cast(ClassVar[Properties], ...)
20 TEXT_SUB = cast(ClassVar[Properties], ...)
21
22 class Capabilities(IntEnum):
23 none = cast(int, ...)
24 draw_horiz_band = cast(int, ...)
25 dr1 = cast(int, ...)
26 hwaccel = cast(int, ...)
27 delay = cast(int, ...)
28 small_last_frame = cast(int, ...)
29 hwaccel_vdpau = cast(int, ...)
30 subframes = cast(int, ...)
31 experimental = cast(int, ...)
32 channel_conf = cast(int, ...)
33 neg_linesizes = cast(int, ...)
34 frame_threads = cast(int, ...)
35 slice_threads = cast(int, ...)
36 param_change = cast(int, ...)
37 auto_threads = cast(int, ...)
38 variable_frame_size = cast(int, ...)
39 avoid_probing = cast(int, ...)
40 hardware = cast(int, ...)
41 hybrid = cast(int, ...)
42 encoder_reordered_opaque = cast(int, ...)
43 encoder_flush = cast(int, ...)
44 encoder_recon_frame = cast(int, ...)
45
46 class UnknownCodecError(ValueError): ...
47
48 class Codec:
49 @property
50 def is_encoder(self) -> bool: ...
51 @property
52 def is_decoder(self) -> bool: ...
53 @property
54 def mode(self) -> Literal["r", "w"]: ...
55 @property
56 def name(self) -> str: ...
57 @property
58 def canonical_name(self) -> str: ...
59 @property
60 def long_name(self) -> str: ...
61 @property
62 def type(
63 self,
64 ) -> Literal["video", "audio", "data", "subtitle", "attachment", "unknown"]: ...
65 @property
66 def id(self) -> int: ...
67 frame_rates: list[Fraction] | None
68 audio_rates: list[int] | None
69 video_formats: list[VideoFormat] | None
70 audio_formats: list[AudioFormat] | None
71
72 @property
73 def properties(self) -> int: ...
74 @property
75 def intra_only(self) -> bool: ...
76 @property
77 def lossy(self) -> bool: ...
78 @property
79 def lossless(self) -> bool: ...
80 @property
81 def reorder(self) -> bool: ...
82 @property
83 def bitmap_sub(self) -> bool: ...
84 @property
85 def text_sub(self) -> bool: ...
86 @property
87 def capabilities(self) -> int: ...
88 @property
89 def experimental(self) -> bool: ...
90 @property
91 def delay(self) -> bool: ...
92 def __init__(self, name: str, mode: Literal["r", "w"] = "r") -> None: ...
93 @overload
94 def create(self, kind: Literal["video"]) -> VideoCodecContext: ...
95 @overload
96 def create(self, kind: Literal["audio"]) -> AudioCodecContext: ...
97 @overload
98 def create(self, kind: Literal["subtitle"]) -> SubtitleCodecContext: ...
99 @overload
100 def create(self, kind: None = None) -> CodecContext: ...
101 @overload
102 def create(
103 self, kind: Literal["video", "audio", "subtitle"] | None = None
104 ) -> (
105 VideoCodecContext | AudioCodecContext | SubtitleCodecContext | CodecContext
106 ): ...
107
108 codecs_available: set[str]
109
110 def dump_codecs() -> None: ...
111 def dump_hwconfigs() -> None: ...
112
113 PixFmtLike = str | VideoFormat
114
115 def find_best_pix_fmt_of_list(
116 pix_fmts: Sequence[PixFmtLike],
117 src_pix_fmt: PixFmtLike,
118 has_alpha: bool = False,
119 ) -> tuple[VideoFormat | None, int]:
120 """
121 Find the best pixel format to convert to given a source format.
122
123 Wraps :ffmpeg:`avcodec_find_best_pix_fmt_of_list`.
124
125 :param pix_fmts: Iterable of pixel formats to choose from (str or VideoFormat).
126 :param src_pix_fmt: Source pixel format (str or VideoFormat).
127 :param bool has_alpha: Whether the source alpha channel is used.
128 :return: (best_format, loss): best_format is the best matching pixel format from
129 the list, or None if no suitable format was found; loss is Combination of flags informing you what kind of losses will occur.
130 :rtype: (VideoFormat | None, int)
131
132 Note on loss: it is a bitmask of FFmpeg loss flags describing what kinds of information would be lost converting from src_pix_fmt to best_format (e.g. loss of alpha, chroma, colorspace, resolution, bit depth, etc.). Multiple losses can be present at once, so the value is meant to be interpreted with bitwise & against FFmpeg's FF_LOSS_* constants.
133 For exact behavior see: libavutil/pixdesc.c/get_pix_fmt_score() in ffmpeg source code.
134 """
135 ...