decoder multithreading

This commit is contained in:
2025-10-04 17:39:37 +02:00
parent 04448df101
commit 639a20bca9
3 changed files with 151 additions and 9 deletions

View File

@ -21,7 +21,7 @@ from .frame import Frame
class Decoder:
__slots__ = '_context'
def __init__(self, stream):
def __init__(self, stream, thread_count):
self._context = libav.codec_alloc_context(stream.codec)
if not self._context:
raise MemoryError
@ -29,6 +29,9 @@ class Decoder:
if errcode < 0:
libav.codec_free_context(self._context)
raise Exception("Failed to set context parameters")
if thread_count > 1:
self._context.contents.thread_count = thread_count
self._context.contents.thread_type = libav.FF_THREAD_FRAME
errcode = libav.codec_open(self._context, stream.codec)
if errcode < 0:
libav.codec_free_context(self._context)