Skip to content

Commit e7bbef6

Browse files
committed
Expose global_quality in CodecContext
1 parent b7ad8dc commit e7bbef6

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ We are operating with `semantic versioning <https://semver.org>`_.
2828
v17.0.2 (next)
2929
--------------
3030

31+
Features:
32+
- Expose ``AVCodecContext.global_quality`` by :gh-user:`WyattBlue` in (:pr:`2246`).
33+
3134
Fixes:
3235

3336

av/codec/context.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,23 @@ def codec_tag(self, value):
590590
else:
591591
raise ValueError("Codec tag should be a 4 character string.")
592592

593+
@property
594+
@cython.cdivision(True)
595+
def global_quality(self):
596+
"""Global quality for codecs which cannot change it per frame.
597+
598+
Stored internally in lambda units; this property converts to/from
599+
QP units using ``FF_QP2LAMBDA``.
600+
601+
Wraps :ffmpeg:`AVCodecContext.global_quality`.
602+
603+
"""
604+
return self.ptr.global_quality // lib.FF_QP2LAMBDA
605+
606+
@global_quality.setter
607+
def global_quality(self, value: cython.int):
608+
self.ptr.global_quality = value * lib.FF_QP2LAMBDA
609+
593610
@property
594611
def bit_rate(self):
595612
return self.ptr.bit_rate if self.ptr.bit_rate > 0 else None

av/codec/context.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class CodecContext:
6262
extradata: bytes | None
6363
time_base: Fraction
6464
codec_tag: str
65+
global_quality: int
6566
bit_rate: int | None
6667
bit_rate_tolerance: int
6768
thread_count: int

include/avutil.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ cdef extern from "libavutil/avutil.h" nogil:
1818
cdef char* avutil_configuration()
1919
cdef char* avutil_license()
2020

21+
int FF_QP2LAMBDA
22+
2123
cdef enum AVPictureType:
2224
AV_PICTURE_TYPE_NONE
2325
AV_PICTURE_TYPE_I

tests/test_codec_context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def iter_raw_frames(
6868

6969

7070
class TestCodecContext(TestCase):
71+
def test_global_quality(self):
72+
ctx = Codec("mpeg4", "w").create()
73+
ctx.global_quality = 5
74+
assert ctx.global_quality == 5
75+
7176
def test_skip_frame_default(self):
7277
ctx = Codec("png", "w").create()
7378
assert ctx.skip_frame == "DEFAULT"

0 commit comments

Comments
 (0)