@@ -37,7 +37,6 @@ cdef AudioFrame alloc_audio_frame():
37
37
38
38
39
39
cdef class AudioFrame(Frame):
40
-
41
40
""" A frame of audio."""
42
41
43
42
def __cinit__ (self , format = " s16" , layout = " stereo" , samples = 0 , align = 1 ):
@@ -61,7 +60,6 @@ cdef class AudioFrame(Frame):
61
60
self .ptr.channels = self .layout.nb_channels
62
61
63
62
if self .layout.channels and nb_samples:
64
-
65
63
# Cleanup the old buffer.
66
64
lib.av_freep(& self ._buffer)
67
65
@@ -95,15 +93,9 @@ cdef class AudioFrame(Frame):
95
93
self .format = get_audio_format(< lib.AVSampleFormat> self .ptr.format)
96
94
97
95
def __repr__ (self ):
98
- return " <av.%s %d , pts=%s , %d samples at %d Hz, %s , %s at 0x%x >" % (
99
- self .__class__.__name__ ,
100
- self .index,
101
- self .pts,
102
- self .samples,
103
- self .rate,
104
- self .layout.name,
105
- self .format.name,
106
- id (self ),
96
+ return (
97
+ f" <av.{self.__class__.__name__} {self.index} pts={self.pts}, {self.samples} "
98
+ f" samples at {self.rate}Hz, {self.layout.name}, {self.format.name} at 0x{id(self):x}"
107
99
)
108
100
109
101
@staticmethod
@@ -117,7 +109,9 @@ cdef class AudioFrame(Frame):
117
109
try :
118
110
dtype = np.dtype(format_dtypes[format])
119
111
except KeyError :
120
- raise ValueError (" Conversion from numpy array with format `%s ` is not yet supported" % format)
112
+ raise ValueError (
113
+ f" Conversion from numpy array with format `{format}` is not yet supported"
114
+ )
121
115
122
116
# check input format
123
117
nb_channels = len (AudioLayout(layout).channels)
@@ -184,25 +178,21 @@ cdef class AudioFrame(Frame):
184
178
"""
185
179
import numpy as np
186
180
187
- # map avcodec type to numpy type
188
181
try :
189
182
dtype = np.dtype(format_dtypes[self .format.name])
190
183
except KeyError :
191
- raise ValueError (" Conversion from {!r} format to numpy array is not supported." .format( self .format.name) )
184
+ raise ValueError (f " Conversion from {self.format.name !r} format to numpy array is not supported." )
192
185
193
186
if self .format.is_planar:
194
187
count = self .samples
195
188
else :
196
189
count = self .samples * len (self .layout.channels)
197
190
198
- # convert and return data
199
191
return np.vstack([np.frombuffer(x, dtype = dtype, count = count) for x in self .planes])
200
192
201
193
def __getattribute__ (self , attribute ):
202
- " This method should be deleted when `frame.index` is removed."
203
- if attribute == ' index' :
204
- warnings.warn(
205
- " Using `frame.index` is deprecated." ,
206
- AVDeprecationWarning
207
- )
194
+ # This method should be deleted when `frame.index` is removed
195
+ if attribute == " index" :
196
+ warnings.warn(" Using `frame.index` is deprecated." , AVDeprecationWarning)
197
+
208
198
return Frame.__getattribute__ (self , attribute)
0 commit comments