diff --git a/python/ftl/libde265.py b/python/ftl/libde265.py index 74a1dcedbb74e3a2b2cbf26f27d3437dae04ff77..edf78beae628b5eb9a0fcb02d6657ad97ce70e2c 100644 --- a/python/ftl/libde265.py +++ b/python/ftl/libde265.py @@ -25,6 +25,14 @@ from enum import IntEnum import numpy as np +import os + +# default number of worker threads for decoder: half of os.cpu_count() + +_threads = os.cpu_count() // 2 +if _threads is None: + _threads = 1 + # error codes copied from header (de265.h) class libde265error(IntEnum): @@ -119,7 +127,7 @@ libde265.de265_get_image_plane.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes libde265.de265_get_image_plane.restype = ctypes.POINTER(ctypes.c_char) class Decoder: - def __init__(self, size, threads=1): + def __init__(self, size, threads=_threads): self._size = size self._more = ctypes.c_int() self._out_stride = ctypes.c_int()