This commit is contained in:
2025-10-03 17:07:17 +02:00
parent dfd0902256
commit b31704420f
3 changed files with 15 additions and 6 deletions

View File

@ -5,7 +5,7 @@ from .packet import Packet
from .frame import Frame
class Decoder:
__slots__ = '_context', '_index'
__slots__ = '_context'
def __init__(self, stream):
self._context = libav.codec_alloc_context(stream.codec)
@ -19,7 +19,6 @@ class Decoder:
if errcode < 0:
libav.codec_free_context(self._context)
raise Exception("Failed to open codec context")
self._index = 0
def __del__(self):
if self._context:
@ -46,3 +45,6 @@ class Decoder:
errstring = libav.strerror(errcode)
raise Exception(f"Failed to send packet: {errstring}")
return self._receive()
def flush(self):
return self.decode(None)

View File

@ -22,6 +22,12 @@ class Demuxer:
self.video_stream = self._find_stream(libav.AVMEDIA_TYPE_VIDEO)
self.audio_stream = self._find_stream(libav.AVMEDIA_TYPE_AUDIO)
@property
def nb_streams(self):
if not self._context:
return 0
return self._context.contents.nb_streams
def _find_stream(self, type):
index, codec_ref = libav.format_find_best_stream(self._context, type)
if index < 0 or not codec_ref: