diff --git a/av/video/codeccontext.pyi b/av/video/codeccontext.pyi index da72053c4..09665fb2d 100644 --- a/av/video/codeccontext.pyi +++ b/av/video/codeccontext.pyi @@ -29,6 +29,7 @@ class VideoCodecContext(CodecContext): qmin: int qmax: int type: Literal["video"] + global_quality: int def encode(self, frame: VideoFrame | None = None) -> list[Packet]: ... def encode_lazy(self, frame: VideoFrame | None = None) -> Iterator[Packet]: ... diff --git a/av/video/codeccontext.pyx b/av/video/codeccontext.pyx index e82e56e91..8a2561632 100644 --- a/av/video/codeccontext.pyx +++ b/av/video/codeccontext.pyx @@ -368,3 +368,21 @@ cdef class VideoCodecContext(CodecContext): @qmax.setter def qmax(self, value): self.ptr.qmax = value + + @property + def global_quality(self): + """ + Global quality for codecs which cannot change it per frame. + For example Intel QSV encoders like hevc_qsv. + + Wraps :ffmpeg:`AVCodecContext.global_quality`. + + :type: int + """ + FF_QP2LAMBDA = 118 # from avutil.h + return int(self.ptr.global_quality / FF_QP2LAMBDA) + + @global_quality.setter + def global_quality(self, value): + FF_QP2LAMBDA = 118 # from avutil.h + self.ptr.global_quality = int(value * FF_QP2LAMBDA)