Skip to content

Commit

Permalink
Remove deprecated methods
Browse files Browse the repository at this point in the history
The following deprecated methods are removed:

- AudioFrame.to_nd_array
- VideoFrame.to_nd_array
- Stream.seek
  • Loading branch information
jlaine committed Mar 7, 2022
1 parent b9eb268 commit 9a7b7b0
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 69 deletions.
3 changes: 0 additions & 3 deletions av/audio/frame.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from av.audio.format cimport get_audio_format
from av.audio.layout cimport get_audio_layout
from av.audio.plane cimport AudioPlane
from av.deprecation import renamed_attr
from av.error cimport err_check
from av.utils cimport check_ndarray, check_ndarray_shape

Expand Down Expand Up @@ -195,5 +194,3 @@ cdef class AudioFrame(Frame):

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

to_nd_array = renamed_attr('to_ndarray')
15 changes: 0 additions & 15 deletions av/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ from av.utils cimport (
to_avrational
)

from av import deprecation


cdef object _cinit_bypass_sentinel = object()

Expand Down Expand Up @@ -175,19 +173,6 @@ cdef class Stream(object):
"""
return self.codec_context.decode(packet)

@deprecation.method
def seek(self, offset, **kwargs):
"""
.. seealso:: :meth:`.InputContainer.seek` for documentation on parameters.
The only difference is that ``offset`` will be interpreted in
:attr:`.Stream.time_base` when ``whence == 'time'``.
.. deprecated:: 6.1.0
Use :meth:`.InputContainer.seek` with ``stream`` argument instead.
"""
self.container.seek(offset, stream=self, **kwargs)

property id:
"""
The format-specific ID of this stream.
Expand Down
4 changes: 0 additions & 4 deletions av/video/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ from av.utils cimport check_ndarray, check_ndarray_shape
from av.video.format cimport VideoFormat, get_pix_fmt, get_video_format
from av.video.plane cimport VideoPlane

from av.deprecation import renamed_attr


cdef object _cinit_bypass_sentinel

Expand Down Expand Up @@ -276,8 +274,6 @@ cdef class VideoFrame(Frame):
else:
raise ValueError('Conversion to numpy array with format `%s` is not yet supported' % frame.format.name)

to_nd_array = renamed_attr('to_ndarray')

@staticmethod
def from_image(img):
"""
Expand Down
17 changes: 0 additions & 17 deletions tests/test_audioframe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import warnings

import numpy

from av import AudioFrame
from av.deprecation import AttributeRenamedWarning

from .common import TestCase

Expand Down Expand Up @@ -82,20 +79,6 @@ def test_basic_to_ndarray(self):
self.assertEqual(array.dtype, "i2")
self.assertEqual(array.shape, (2, 160))

def test_basic_to_nd_array(self):
frame = AudioFrame(format="s16p", layout="stereo", samples=160)
with warnings.catch_warnings(record=True) as recorded:
array = frame.to_nd_array()
self.assertEqual(array.shape, (2, 160))

# check deprecation warning
self.assertEqual(len(recorded), 1)
self.assertEqual(recorded[0].category, AttributeRenamedWarning)
self.assertEqual(
str(recorded[0].message),
"AudioFrame.to_nd_array is deprecated; please use AudioFrame.to_ndarray.",
)

def test_ndarray_dbl(self):
layouts = [
("dbl", "mono", "f8", (1, 160)),
Expand Down
16 changes: 2 additions & 14 deletions tests/test_seek.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import division

import unittest
import warnings

import av

Expand All @@ -27,7 +26,6 @@ class TestSeek(TestCase):
def test_seek_float(self):
container = av.open(fate_suite("h264/interlaced_crop.mp4"))
self.assertRaises(TypeError, container.seek, 1.0)
self.assertRaises(TypeError, container.streams.video[0].seek, 1.0)

def test_seek_int64(self):
# Assert that it accepts large values.
Expand Down Expand Up @@ -128,7 +126,7 @@ def test_decode_half(self):

self.assertEqual(frame_count, total_frame_count - target_frame)

def test_stream_seek(self, use_deprecated_api=False):
def test_stream_seek(self):

container = av.open(fate_suite("h264/interlaced_crop.mp4"))

Expand All @@ -147,14 +145,7 @@ def test_stream_seek(self, use_deprecated_api=False):
target_sec = target_frame * 1 / rate

target_timestamp = int(target_sec / time_base) + video_stream.start_time

if use_deprecated_api:
with warnings.catch_warnings(record=True) as captured:
video_stream.seek(target_timestamp)
self.assertEqual(len(captured), 1)
self.assertIn("Stream.seek is deprecated.", captured[0].message.args[0])
else:
container.seek(target_timestamp, stream=video_stream)
container.seek(target_timestamp, stream=video_stream)

current_frame = None
frame_count = 0
Expand All @@ -173,9 +164,6 @@ def test_stream_seek(self, use_deprecated_api=False):

self.assertEqual(frame_count, total_frame_count - target_frame)

def test_deprecated_stream_seek(self):
self.test_stream_seek(use_deprecated_api=True)


if __name__ == "__main__":
unittest.main()
16 changes: 0 additions & 16 deletions tests/test_videoframe.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from unittest import SkipTest
import warnings

import numpy

from av import VideoFrame
from av.deprecation import AttributeRenamedWarning

from .common import Image, TestCase, fate_png

Expand Down Expand Up @@ -159,20 +157,6 @@ def test_basic_to_ndarray(self):
array = frame.to_ndarray()
self.assertEqual(array.shape, (480, 640, 3))

def test_basic_to_nd_array(self):
frame = VideoFrame(640, 480, "rgb24")
with warnings.catch_warnings(record=True) as recorded:
array = frame.to_nd_array()
self.assertEqual(array.shape, (480, 640, 3))

# check deprecation warning
self.assertEqual(len(recorded), 1)
self.assertEqual(recorded[0].category, AttributeRenamedWarning)
self.assertEqual(
str(recorded[0].message),
"VideoFrame.to_nd_array is deprecated; please use VideoFrame.to_ndarray.",
)

def test_ndarray_gray(self):
array = numpy.random.randint(0, 256, size=(480, 640), dtype=numpy.uint8)
for format in ["gray", "gray8"]:
Expand Down

0 comments on commit 9a7b7b0

Please sign in to comment.