Skip to content

Commit

Permalink
Deprecate frame.index
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSchiff committed Feb 17, 2024
1 parent 9c1589e commit 6c02a2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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 @@ -90,6 +90,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 @@ -319,7 +330,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 6c02a2e

Please sign in to comment.