Skip to content

Commit

Permalink
Deprecate frame.index
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSchiff authored and WyattBlue committed Feb 17, 2024
1 parent 1eb416b commit 17e86d1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions av/audio/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ from av.audio.plane cimport AudioPlane
from av.error cimport err_check
from av.utils cimport check_ndarray, check_ndarray_shape

import warnings

from av.deprecation import AVDeprecationWarning


cdef object _cinit_bypass_sentinel

Expand Down Expand Up @@ -193,3 +197,12 @@ cdef class AudioFrame(Frame):

# convert and return data
return np.vstack([np.frombuffer(x, dtype=dtype, count=count) for x in self.planes])

def __getattribute__(self, attribute):
"This method should be deleted when `frame.index` is removed."
if attribute == 'index':
warnings.warn(
"Using `frame.index` is deprecated.",
AVDeprecationWarning
)
return Frame.__getattribute__(self, attribute)
13 changes: 13 additions & 0 deletions av/video/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ from av.utils cimport check_ndarray, check_ndarray_shape
from av.video.format cimport get_pix_fmt, get_video_format
from av.video.plane cimport VideoPlane, YUVPlanes

import warnings

from av.deprecation import AVDeprecationWarning


cdef object _cinit_bypass_sentinel

Expand Down Expand Up @@ -580,3 +584,12 @@ cdef class VideoFrame(Frame):
copy_array_to_plane(array, frame.planes[0], 1 if array.ndim == 2 else array.shape[2])

return frame

def __getattribute__(self, attribute):
"This method should be deleted when `frame.index` is removed."
if attribute == 'index':
warnings.warn(
"Using `frame.index` is deprecated.",
AVDeprecationWarning
)
return Frame.__getattribute__(self, attribute)
13 changes: 12 additions & 1 deletion tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ def test_decoder_gop_size(self):
"Using VideoCodecContext.gop_size for decoders is deprecated.",
)

def test_frame_index(self):
container = av.open(fate_suite("h264/interlaced_crop.mp4"))
stream = container.streams[0]
for frame in container.decode(stream):
with warnings.catch_warnings(record=True) as captured:
self.assertIsInstance(frame.index, int)
self.assertEqual(
captured[0].message.args[0],
"Using `frame.index` is deprecated.",
)

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

Expand Down Expand Up @@ -325,7 +336,7 @@ def video_encoding(self, codec_name, options={}, codec_tag=None):
self.assertEqual(frame.height, height)
self.assertEqual(frame.format.name, pix_fmt)
if frame.key_frame:
keyframe_indices.append(frame.index)
keyframe_indices.append(decoded_frame_count)

self.assertEqual(frame_count, decoded_frame_count)

Expand Down

0 comments on commit 17e86d1

Please sign in to comment.