Skip to content

Commit

Permalink
Deprecate VideoCodecContext.gop_size for decoders (fixes: #1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSchiff authored and jlaine committed Jan 10, 2024
1 parent bf87dc2 commit 1962443
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions av/video/codeccontext.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from libc.stdint cimport int64_t
cimport libav as lib

Expand All @@ -9,6 +11,8 @@ from av.video.format cimport VideoFormat, get_pix_fmt, get_video_format
from av.video.frame cimport VideoFrame, alloc_video_frame
from av.video.reformatter cimport VideoReformatter

from av.deprecation import AVDeprecationWarning


cdef class VideoCodecContext(CodecContext):

Expand Down Expand Up @@ -126,10 +130,21 @@ cdef class VideoCodecContext(CodecContext):
self.framerate = value

property gop_size:
"""This only makes sense for encoders."""
def __get__(self):
if self.is_decoder:
warnings.warn(
"Using VideoCodecContext.gop_size for decoders is deprecated.",
AVDeprecationWarning
)
return self.ptr.gop_size

def __set__(self, int value):
if self.is_decoder:
warnings.warn(
"Using VideoCodecContext.gop_size for decoders is deprecated.",
AVDeprecationWarning
)
self.ptr.gop_size = value

property sample_aspect_ratio:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def test_decoder_extradata(self):
self.assertEqual(ctx.extradata, None)
self.assertEqual(ctx.extradata_size, 0)

def test_decoder_gop_size(self):
ctx = av.codec.Codec("h264", "r").create()

with warnings.catch_warnings(record=True) as captured:
self.assertIsInstance(ctx.gop_size, int)
self.assertEqual(
captured[0].message.args[0],
"Using VideoCodecContext.gop_size for decoders is deprecated.",
)

def test_decoder_timebase(self):
ctx = av.codec.Codec("h264", "r").create()

Expand Down
2 changes: 0 additions & 2 deletions tests/test_file_probing.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def test_stream_probing(self):
self.assertEqual(stream.display_aspect_ratio, Fraction(4, 3))
self.assertEqual(stream.format.name, "yuv420p")
self.assertFalse(stream.has_b_frames)
self.assertEqual(stream.gop_size, 12)
self.assertEqual(stream.height, 576)
self.assertEqual(stream.max_bit_rate, None)
self.assertEqual(stream.sample_aspect_ratio, Fraction(16, 15))
Expand Down Expand Up @@ -383,7 +382,6 @@ def test_stream_probing(self):
self.assertEqual(stream.display_aspect_ratio, None)
self.assertEqual(stream.format, None)
self.assertFalse(stream.has_b_frames)
self.assertEqual(stream.gop_size, 12)
self.assertEqual(stream.height, 0)
self.assertEqual(stream.max_bit_rate, None)
self.assertEqual(stream.sample_aspect_ratio, None)
Expand Down

0 comments on commit 1962443

Please sign in to comment.