Skip to content

Commit f8dddb9

Browse files
committed
Fix #2161 null check for get_media_type_str
1 parent 642c6de commit f8dddb9

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

av/codec/codec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ def type(self):
172172
E.g: ``'audio'``, ``'video'``, ``'subtitle'``.
173173
174174
"""
175-
return lib.av_get_media_type_string(self.ptr.type)
175+
media_type = lib.av_get_media_type_string(self.ptr.type)
176+
return "unknown" if media_type == cython.NULL else media_type
176177

177178
@property
178179
def id(self):

av/codec/codec.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class Codec:
6161
@property
6262
def long_name(self) -> str: ...
6363
@property
64-
def type(self) -> Literal["video", "audio", "data", "subtitle", "attachment"]: ...
64+
def type(
65+
self,
66+
) -> Literal["video", "audio", "data", "subtitle", "attachment", "unknown"]: ...
6567
@property
6668
def id(self) -> int: ...
6769
frame_rates: list[Fraction] | None

av/stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ def type(self):
275275
276276
:type: Literal["audio", "video", "subtitle", "data", "attachment"]
277277
"""
278-
return lib.av_get_media_type_string(self.ptr.codecpar.codec_type)
278+
media_type = lib.av_get_media_type_string(self.ptr.codecpar.codec_type)
279+
return "unknown" if media_type == cython.NULL else media_type
279280

280281

281282
@cython.cclass

av/stream.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Stream:
4848
disposition: Disposition
4949
frames: int
5050
language: str | None
51-
type: Literal["video", "audio", "data", "subtitle", "attachment"]
51+
type: Literal["video", "audio", "data", "subtitle", "attachment", "unknown"]
5252

5353
# From context
5454
codec_tag: str

0 commit comments

Comments
 (0)