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

Make Subtitle an abstract base class #1441

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading