Skip to content
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
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ We are operating with `semantic versioning <https://semver.org>`_.
Note that they these tags will not actually close the issue/PR until they
are merged into the "default" branch.

v15.0.0 (Unreleased)
--------------------

Major:

- Make ``SubtitleStream.decode()`` return the list of subtitles directly, without the intermediate ``SubtitleSet``.

v14.4.0
-------

Expand Down
3 changes: 2 additions & 1 deletion av/subtitles/codeccontext.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from av.codec.context cimport CodecContext
from av.packet cimport Packet


cdef class SubtitleCodecContext(CodecContext):
pass
cpdef decode2(self, Packet packet)
55 changes: 55 additions & 0 deletions av/subtitles/codeccontext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import cython
from cython.cimports import libav as lib
from cython.cimports.av.error import err_check
from cython.cimports.av.packet import Packet
from cython.cimports.av.subtitles.subtitle import SubtitleProxy, SubtitleSet


@cython.cclass
class SubtitleCodecContext(CodecContext):
@cython.cfunc
def _send_packet_and_recv(self, packet: Packet | None):
if packet is None:
raise RuntimeError("packet cannot be None")

proxy: SubtitleProxy = SubtitleProxy()
got_frame: cython.int = 0

err_check(
lib.avcodec_decode_subtitle2(
self.ptr,
cython.address(proxy.struct),
cython.address(got_frame),
packet.ptr,
)
)

if got_frame:
return SubtitleSet(proxy)
return []

@cython.ccall
def decode2(self, packet: Packet):
"""
Returns SubtitleSet if you really need it.
"""
if not self.codec.ptr:
raise ValueError("cannot decode unknown codec")

self.open(strict=False)

proxy: SubtitleProxy = SubtitleProxy()
got_frame: cython.int = 0

err_check(
lib.avcodec_decode_subtitle2(
self.ptr,
cython.address(proxy.struct),
cython.address(got_frame),
packet.ptr,
)
)

if got_frame:
return SubtitleSet(proxy)
return None
3 changes: 3 additions & 0 deletions av/subtitles/codeccontext.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Literal

from av.codec.context import CodecContext
from av.packet import Packet
from av.subtitles.subtitle import SubtitleSet

class SubtitleCodecContext(CodecContext):
type: Literal["subtitle"]
def decode2(self, packet: Packet) -> SubtitleSet | None: ...
23 changes: 0 additions & 23 deletions av/subtitles/codeccontext.pyx

This file was deleted.

23 changes: 23 additions & 0 deletions av/subtitles/stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import cython
from cython.cimports.av.packet import Packet
from cython.cimports.av.stream import Stream


@cython.cclass
class SubtitleStream(Stream):
def __getattr__(self, name):
return getattr(self.codec_context, name)

@cython.ccall
def decode(self, packet: Packet | None = None):
"""
Decode a :class:`.Packet` and returns a subtitle object.

:rtype: list[AssSubtitle] | list[BitmapSubtitle]

.. seealso:: This is a passthrough to :meth:`.CodecContext.decode`.
"""
if not packet:
packet = Packet()

return self.codec_context.decode(packet)
7 changes: 5 additions & 2 deletions av/subtitles/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from av.packet import Packet
from av.stream import Stream
from av.subtitles.subtitle import SubtitleSet
from av.subtitles.subtitle import AssSubtitle, BitmapSubtitle, SubtitleSet

class SubtitleStream(Stream):
def decode(self, packet: Packet | None = None) -> list[SubtitleSet]: ...
def decode(
self, packet: Packet | None = None
) -> list[AssSubtitle] | list[BitmapSubtitle]: ...
def decode2(self, packet: Packet) -> SubtitleSet | None: ...
23 changes: 0 additions & 23 deletions av/subtitles/stream.pyx

This file was deleted.

Loading
Loading