Skip to content

Commit

Permalink
Make Subtitle an abstract base class
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Jun 25, 2024
1 parent 7777261 commit 69cab49
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion av/codec/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ cdef class CodecContext:
def skip_frame(self):
"""One of :class:`.SkipType`.
Wraps ffmpeg:`AVCodecContext.skip_frame`.
Wraps :ffmpeg:`AVCodecContext.skip_frame`.
"""
return SkipType._get(self.ptr.skip_frame, create=True)
Expand Down
3 changes: 3 additions & 0 deletions av/subtitles/stream.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
cdef class SubtitleStream(Stream):
"""
A :class:`SubtitleStream` can contain many :class:`SubtitleSet` objects accessible via decoding.
"""
def __getattr__(self, name):
return getattr(self.codec_context, name)
3 changes: 1 addition & 2 deletions av/subtitles/subtitle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class SubtitleSet:
def __iter__(self) -> Iterator[Subtitle]: ...
def __getitem__(self, i: int) -> Subtitle: ...

class Subtitle:
type: Literal[b"none", b"bitmap", b"text", b"ass"]
class Subtitle: ...

class BitmapSubtitle(Subtitle):
type: Literal[b"bitmap"]
Expand Down
11 changes: 8 additions & 3 deletions av/subtitles/subtitle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cdef class SubtitleProxy:


cdef class SubtitleSet:
"""
A :class:`SubtitleSet` can contain many :class:`Subtitle` objects.
"""
def __cinit__(self, SubtitleProxy proxy):
self.proxy = proxy
cdef int i
Expand Down Expand Up @@ -50,9 +53,7 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index):
raise ValueError("subtitle rect index out of range")
cdef lib.AVSubtitleRect *ptr = subtitle.proxy.struct.rects[index]

if ptr.type == lib.SUBTITLE_NONE:
return Subtitle(subtitle, index)
elif ptr.type == lib.SUBTITLE_BITMAP:
if ptr.type == lib.SUBTITLE_BITMAP:
return BitmapSubtitle(subtitle, index)
elif ptr.type == lib.SUBTITLE_TEXT:
return TextSubtitle(subtitle, index)
Expand All @@ -63,6 +64,10 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index):


cdef class Subtitle:
"""
An abstract base class for each concrete type of subtitle.
Wraps :ffmpeg:`AVSubtitleRect`
"""
def __cinit__(self, SubtitleSet subtitle, int index):
if index < 0 or <unsigned int>index >= subtitle.proxy.struct.num_rects:
raise ValueError("subtitle rect index out of range")
Expand Down

0 comments on commit 69cab49

Please sign in to comment.