1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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
|