Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ We are operating with `semantic versioning <https://semver.org>`_.
v17.0.2 (next)
--------------

Features:
- Expose ``AVCodecContext.global_quality`` by :gh-user:`WyattBlue` in (:pr:`2246`).

Fixes:


Expand Down
17 changes: 17 additions & 0 deletions av/codec/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,23 @@ def codec_tag(self, value):
else:
raise ValueError("Codec tag should be a 4 character string.")

@property
@cython.cdivision(True)
def global_quality(self):
"""Global quality for codecs which cannot change it per frame.

Stored internally in lambda units; this property converts to/from
QP units using ``FF_QP2LAMBDA``.

Wraps :ffmpeg:`AVCodecContext.global_quality`.

"""
return self.ptr.global_quality // lib.FF_QP2LAMBDA

@global_quality.setter
def global_quality(self, value: cython.int):
self.ptr.global_quality = value * lib.FF_QP2LAMBDA

@property
def bit_rate(self):
return self.ptr.bit_rate if self.ptr.bit_rate > 0 else None
Expand Down
1 change: 1 addition & 0 deletions av/codec/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CodecContext:
extradata: bytes | None
time_base: Fraction
codec_tag: str
global_quality: int
bit_rate: int | None
bit_rate_tolerance: int
thread_count: int
Expand Down
2 changes: 2 additions & 0 deletions include/avutil.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cdef extern from "libavutil/avutil.h" nogil:
cdef char* avutil_configuration()
cdef char* avutil_license()

int FF_QP2LAMBDA

cdef enum AVPictureType:
AV_PICTURE_TYPE_NONE
AV_PICTURE_TYPE_I
Expand Down
5 changes: 5 additions & 0 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def iter_raw_frames(


class TestCodecContext(TestCase):
def test_global_quality(self):
ctx = Codec("mpeg4", "w").create()
ctx.global_quality = 5
assert ctx.global_quality == 5

def test_skip_frame_default(self):
ctx = Codec("png", "w").create()
assert ctx.skip_frame == "DEFAULT"
Expand Down
Loading