This commit is contained in:
2025-10-03 18:08:09 +02:00
parent 7cf7a8cb9a
commit b0c3fbc1b1
5 changed files with 24 additions and 35 deletions

View File

@ -34,16 +34,16 @@ class Demuxer:
raise Exception("Failed to find stream info")
self.video_stream = self._find_stream(libav.AVMEDIA_TYPE_VIDEO)
if self.video_stream is None:
libav.format_close_input(self._context)
raise Exception("Failed to find a video stream")
self.audio_stream = self._find_stream(libav.AVMEDIA_TYPE_AUDIO)
if self.audio_stream is None:
libav.format_close_input(self._context)
raise Exception("Failed to find an audio stream")
@property
def nb_streams(self):
if not self._context:
return 0
return self._context.contents.nb_streams
def __del__(self):
if self._context:
libav.format_close_input(self._context)
def _find_stream(self, type):
index, codec_ref = libav.format_find_best_stream(self._context, type)
@ -52,6 +52,12 @@ class Demuxer:
parameters = self._context.contents.streams[index].contents.codecpar
return Stream(index, Codec(codec_ref), parameters)
@property
def nb_streams(self):
if not self._context:
return 0
return self._context.contents.nb_streams
def read_packet(self):
if not self._context:
return None
@ -60,7 +66,3 @@ class Demuxer:
if errcode < 0:
return None
return packet
def close(self):
if self._context:
libav.format_close_input(self._context)