Skip to content

Commit

Permalink
Remove frame.index
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Jul 17, 2024
1 parent be56224 commit a6627f8
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 35 deletions.
9 changes: 1 addition & 8 deletions av/audio/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cdef class AudioFrame(Frame):

def __repr__(self):
return (
f"<av.{self.__class__.__name__} {self.index} pts={self.pts}, {self.samples} "
f"<av.{self.__class__.__name__} pts={self.pts}, {self.samples} "
f"samples at {self.rate}Hz, {self.layout.name}, {self.format.name} at 0x{id(self):x}"
)

Expand Down Expand Up @@ -191,10 +191,3 @@ cdef class AudioFrame(Frame):
count = self.samples * len(self.layout.channels)

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)
3 changes: 0 additions & 3 deletions av/codec/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ cdef class CodecContext:
lib.avcodec_flush_buffers(self.ptr)

cdef _setup_decoded_frame(self, Frame frame, Packet packet):

# Propagate our manual times.
# While decoding, frame times are in stream time_base, which PyAV
# is carrying around.
Expand All @@ -489,8 +488,6 @@ cdef class CodecContext:
if packet is not None:
frame._time_base = packet._time_base

frame.index = self.ptr.frame_number - 1

@property
def name(self):
return self.codec.name
Expand Down
7 changes: 0 additions & 7 deletions av/frame.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ from av.sidedata.sidedata cimport _SideDataContainer


cdef class Frame:

cdef lib.AVFrame *ptr

# We define our own time.
cdef lib.AVRational _time_base
cdef _rebase_time(self, lib.AVRational)

cdef _SideDataContainer _side_data

cdef readonly int index

cdef _copy_internal_attributes(self, Frame source, bint data_layout=?)

cdef _init_user_attributes(self)
3 changes: 1 addition & 2 deletions av/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ cdef class Frame:
lib.av_frame_free(&self.ptr)

def __repr__(self):
return f"av.{self.__class__.__name__} #{self.index} pts={self.pts} at 0x{id(self):x}>"
return f"av.{self.__class__.__name__} pts={self.pts} at 0x{id(self):x}>"

cdef _copy_internal_attributes(self, Frame source, bint data_layout=True):
"""Mimic another frame."""
self.index = source.index
self._time_base = source._time_base
lib.av_frame_copy_props(self.ptr, source.ptr)
if data_layout:
Expand Down
4 changes: 2 additions & 2 deletions av/video/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ cdef class VideoFrame(Frame):

def __repr__(self):
return (
f"<av.{self.__class__.__name__} #{self.index}, pts={self.pts} "
f"{self.format.name} {self.width}x{self.height} at 0x{id(self):x}>"
f"<av.{self.__class__.__name__}, pts={self.pts} {self.format.name} "
f"{self.width}x{self.height} at 0x{id(self):x}>"
)

@property
Expand Down
2 changes: 0 additions & 2 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:
int global_quality
int compression_level

int frame_number

int qmin
int qmax
int rc_max_rate
Expand Down
11 changes: 0 additions & 11 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ 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

0 comments on commit a6627f8

Please sign in to comment.