Skip to content

Commit

Permalink
Remove deprecated VideoStream.frame_rate
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Mar 23, 2024
1 parent 3acc918 commit 4e2f0b7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 34 deletions.
3 changes: 3 additions & 0 deletions av/audio/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cdef class AudioStream(Stream):
f" {self.layout.name}, {form} at 0x{id(self):x}>"
)

def __getattr__(self, name):
return getattr(self.codec_context, name)

cpdef encode(self, AudioFrame frame=None):
"""
Encode an :class:`.AudioFrame` and return a list of :class:`.Packet`.
Expand Down
3 changes: 3 additions & 0 deletions av/data/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cdef class DataStream(Stream):
f"{self.name or '<nocodec>'} at 0x{id(self):x}>"
)

def __getattr__(self, name):
return getattr(self.codec_context, name)

def encode(self, frame=None):
return []

Expand Down
13 changes: 0 additions & 13 deletions av/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ cdef class Stream:
f"{self.name or '<nocodec>'} at 0x{id(self):x}>"
)

def __getattr__(self, name):
# Deprecate framerate pass-through as it is not always set.
# See: https://github.com/PyAV-Org/PyAV/issues/1005
if self.ptr.codecpar.codec_type == lib.AVMEDIA_TYPE_VIDEO and name in ("framerate", "rate"):
warnings.warn(
f"VideoStream.{name} is deprecated as it is not always set; please use VideoStream.average_rate.",
AVDeprecationWarning
)

# Convenience getter for codec context properties.
if self.codec_context is not None:
return getattr(self.codec_context, name)

def __setattr__(self, name, value):
if name == "id":
self._set_id(value)
Expand Down
3 changes: 2 additions & 1 deletion av/subtitles/stream.pyx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cdef class SubtitleStream(Stream):
pass
def __getattr__(self, name):
return getattr(self.codec_context, name)
6 changes: 6 additions & 0 deletions av/video/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ cdef class VideoStream(Stream):
f"{self.codec_context.height} at 0x{id(self):x}>"
)

def __getattr__(self, name):
if name in ("framerate", "rate"):
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")

return getattr(self.codec_context, name)

cpdef encode(self, VideoFrame frame=None):
"""
Encode an :class:`.VideoFrame` and return a list of :class:`.Packet`.
Expand Down
23 changes: 3 additions & 20 deletions tests/test_file_probing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from fractions import Fraction

import av
Expand Down Expand Up @@ -169,9 +168,6 @@ def test_stream_probing(self):
self.assertTrue(str(stream).startswith("<av.DataStream #0 data/<nocodec> at "))

# actual stream properties
self.assertEqual(stream.average_rate, None)
self.assertEqual(stream.base_rate, None)
self.assertEqual(stream.guessed_rate, None)
self.assertEqual(stream.duration, 37537)
self.assertEqual(stream.frames, 0)
self.assertEqual(stream.id, 1)
Expand All @@ -189,9 +185,7 @@ def test_stream_probing(self):
self.assertEqual(stream.start_time, 0)
self.assertEqual(stream.time_base, Fraction(1, 90000))
self.assertEqual(stream.type, "data")

# codec context properties
self.assertEqual(stream.codec, None)
self.assertEqual(hasattr(stream, "codec"), False)


class TestSubtitleProbe(TestCase):
Expand Down Expand Up @@ -307,19 +301,8 @@ def test_stream_probing(self):
self.assertIn(stream.coded_width, (720, 0))
self.assertIn(stream.coded_height, (576, 0))

# Deprecated properties.
with warnings.catch_warnings(record=True) as captured:
stream.framerate
self.assertEqual(
captured[0].message.args[0],
"VideoStream.framerate is deprecated as it is not always set; please use VideoStream.average_rate.",
)
with warnings.catch_warnings(record=True) as captured:
stream.rate
self.assertEqual(
captured[0].message.args[0],
"VideoStream.rate is deprecated as it is not always set; please use VideoStream.average_rate.",
)
self.assertEqual(hasattr(stream, "framerate"), False)
self.assertEqual(hasattr(stream, "rate"), False)


class TestVideoProbeCorrupt(TestCase):
Expand Down

0 comments on commit 4e2f0b7

Please sign in to comment.