diff --git a/.gitignore b/.gitignore index 6e5a2b48e..2e71c06bc 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ /ipch /msvc-projects /src +/docs/_ffmpeg # Testing. *.spyderproject diff --git a/av/data/stream.pyx b/av/data/stream.pyx index e8d6624e2..8136c6395 100644 --- a/av/data/stream.pyx +++ b/av/data/stream.pyx @@ -3,11 +3,10 @@ cimport libav as lib cdef class DataStream(Stream): def __repr__(self): - cls_name = self.__class__.__name__ - _type = self.type or "" - name = self.name or "" - - return f"" + return ( + f"'}/" + f"{self.name or ''} at 0x{id(self):x}>" + ) def encode(self, frame=None): return [] diff --git a/av/subtitles/codeccontext.pyx b/av/subtitles/codeccontext.pyx index c3f433abe..227add919 100644 --- a/av/subtitles/codeccontext.pyx +++ b/av/subtitles/codeccontext.pyx @@ -6,7 +6,6 @@ from av.subtitles.subtitle cimport SubtitleProxy, SubtitleSet cdef class SubtitleCodecContext(CodecContext): - cdef _send_packet_and_recv(self, Packet packet): cdef SubtitleProxy proxy = SubtitleProxy() diff --git a/av/subtitles/stream.pyx b/av/subtitles/stream.pyx index aea5c57e2..8da6043f0 100644 --- a/av/subtitles/stream.pyx +++ b/av/subtitles/stream.pyx @@ -1,3 +1,2 @@ - cdef class SubtitleStream(Stream): pass diff --git a/av/subtitles/subtitle.pyx b/av/subtitles/subtitle.pyx index 9e98f01aa..5b2fc8a4a 100644 --- a/av/subtitles/subtitle.pyx +++ b/av/subtitles/subtitle.pyx @@ -7,18 +7,13 @@ cdef class SubtitleProxy: cdef class SubtitleSet: - def __cinit__(self, SubtitleProxy proxy): self.proxy = proxy cdef int i self.rects = tuple(build_subtitle(self, i) for i in range(self.proxy.struct.num_rects)) def __repr__(self): - return "<%s.%s at 0x%x>" % ( - self.__class__.__module__, - self.__class__.__name__, - id(self), - ) + return f"<{self.__class__.__module__}.{self.__class__.__name__} at 0x{id(self):x}>" @property def format(self): return self.proxy.struct.format @@ -64,7 +59,6 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index): cdef class Subtitle: - def __cinit__(self, SubtitleSet subtitle, int index): if index < 0 or index >= subtitle.proxy.struct.num_rects: raise ValueError("subtitle rect index out of range") @@ -80,18 +74,13 @@ cdef class Subtitle: elif self.ptr.type == lib.SUBTITLE_ASS: self.type = b"ass" else: - raise ValueError("unknown subtitle type %r" % self.ptr.type) + raise ValueError(f"unknown subtitle type {self.ptr.type!r}") def __repr__(self): - return "<%s.%s at 0x%x>" % ( - self.__class__.__module__, - self.__class__.__name__, - id(self), - ) + return f"<{self.__class__.__module__}.{self.__class__.__name__} at 0x{id(self):x}>" cdef class BitmapSubtitle(Subtitle): - def __cinit__(self, SubtitleSet subtitle, int index): self.planes = tuple( BitmapSubtitlePlane(self, i) @@ -100,14 +89,9 @@ cdef class BitmapSubtitle(Subtitle): ) def __repr__(self): - return "<%s.%s %dx%d at %d,%d; at 0x%x>" % ( - self.__class__.__module__, - self.__class__.__name__, - self.width, - self.height, - self.x, - self.y, - id(self), + return ( + f"<{self.__class__.__module__}.{self.__class__.__name__} " + f"{self.width}x{self.height} at {self.x},{self.y}; at 0x{id(self):x}>" ) @property @@ -132,9 +116,7 @@ cdef class BitmapSubtitle(Subtitle): cdef class BitmapSubtitlePlane: - def __cinit__(self, BitmapSubtitle subtitle, int index): - if index >= 4: raise ValueError("BitmapSubtitles have only 4 planes") if not subtitle.ptr.linesize[index]: @@ -146,34 +128,29 @@ cdef class BitmapSubtitlePlane: self._buffer = subtitle.ptr.data[index] # New-style buffer support. - def __getbuffer__(self, Py_buffer *view, int flags): PyBuffer_FillInfo(view, self, self._buffer, self.buffer_size, 0, flags) cdef class TextSubtitle(Subtitle): - def __repr__(self): - return "<%s.%s %r at 0x%x>" % ( - self.__class__.__module__, - self.__class__.__name__, - self.text, - id(self), + return ( + f"<{self.__class__.__module__}.{self.__class__.__name__} " + f"{self.text!r} at 0x{id(self):x}>" ) @property - def text(self): return self.ptr.text + def text(self): + return self.ptr.text cdef class AssSubtitle(Subtitle): - def __repr__(self): - return "<%s.%s %r at 0x%x>" % ( - self.__class__.__module__, - self.__class__.__name__, - self.ass, - id(self), + return ( + f"<{self.__class__.__module__}.{self.__class__.__name__} " + f"{self.ass!r} at 0x{id(self):x}>" ) @property - def ass(self): return self.ptr.ass + def ass(self): + return self.ptr.ass diff --git a/av/video/codeccontext.pyx b/av/video/codeccontext.pyx index 70bc36d3f..e896b44f0 100644 --- a/av/video/codeccontext.pyx +++ b/av/video/codeccontext.pyx @@ -15,7 +15,6 @@ from av.deprecation import AVDeprecationWarning cdef class VideoCodecContext(CodecContext): - def __cinit__(self, *args, **kwargs): self.last_w = 0 self.last_h = 0 @@ -30,7 +29,6 @@ cdef class VideoCodecContext(CodecContext): self.ptr.time_base.den = self.ptr.framerate.num or lib.AV_TIME_BASE cdef _prepare_frames_for_encode(self, Frame input): - if not input: return [None] diff --git a/av/video/format.pyx b/av/video/format.pyx index c9fac8e90..6ae66c3a2 100644 --- a/av/video/format.pyx +++ b/av/video/format.pyx @@ -4,6 +4,7 @@ cdef object _cinit_bypass_sentinel = object() cdef VideoFormat get_video_format(lib.AVPixelFormat c_format, unsigned int width, unsigned int height): if c_format == lib.AV_PIX_FMT_NONE: return None + cdef VideoFormat format = VideoFormat.__new__(VideoFormat, _cinit_bypass_sentinel) format._init(c_format, width, height) return format @@ -53,9 +54,9 @@ cdef class VideoFormat: def __repr__(self): if self.width or self.height: - return "" % (self.__class__.__name__, self.name, self.width, self.height) + return f"" else: - return "" % (self.__class__.__name__, self.name) + return f"" def __int__(self): return int(self.pix_fmt) @@ -129,7 +130,6 @@ cdef class VideoFormat: cdef class VideoFormatComponent: - def __cinit__(self, VideoFormat format, size_t index): self.format = format self.index = index diff --git a/av/video/frame.pyx b/av/video/frame.pyx index 60a2addf2..4425e18a9 100644 --- a/av/video/frame.pyx +++ b/av/video/frame.pyx @@ -77,9 +77,7 @@ cdef useful_array(VideoPlane plane, unsigned int bytes_per_pixel=1, str dtype="u cdef class VideoFrame(Frame): - def __cinit__(self, width=0, height=0, format="yuv420p"): - if width is _cinit_bypass_sentinel: return @@ -88,7 +86,6 @@ cdef class VideoFrame(Frame): self._init(c_format, width, height) cdef _init(self, lib.AVPixelFormat format, unsigned int width, unsigned int height): - cdef int res = 0 with nogil: @@ -126,14 +123,9 @@ cdef class VideoFrame(Frame): self._np_buffer = None def __repr__(self): - return "" % ( - self.__class__.__name__, - self.index, - self.pts, - self.format.name, - self.width, - self.height, - id(self), + return ( + f"" ) @property @@ -367,7 +359,9 @@ cdef class VideoFrame(Frame): useful_array(frame.planes[1], 2) )).reshape(-1, frame.width) else: - raise ValueError("Conversion to numpy array with format `%s` is not yet supported" % frame.format.name) + raise ValueError( + f"Conversion to numpy array with format `{frame.format.name}` is not yet supported" + ) @staticmethod def from_image(img): diff --git a/av/video/plane.pyx b/av/video/plane.pyx index 6bf03b1bc..908b48716 100644 --- a/av/video/plane.pyx +++ b/av/video/plane.pyx @@ -17,7 +17,7 @@ cdef class VideoPlane(Plane): self.height = component.height break else: - raise RuntimeError("could not find plane %d of %r" % (index, frame.format)) + raise RuntimeError(f"could not find plane {index} of {frame.format!r}") # Sometimes, linesize is negative (and that is meaningful). We are only # insisting that the buffer size be based on the extent of linesize, and diff --git a/av/video/reformatter.pyx b/av/video/reformatter.pyx index ee599b817..b36b646c5 100644 --- a/av/video/reformatter.pyx +++ b/av/video/reformatter.pyx @@ -150,12 +150,8 @@ cdef class VideoReformatter: cdef int brightness, contrast, saturation cdef int ret - if ( - src_colorspace != dst_colorspace or - src_color_range != dst_color_range - ): + if src_colorspace != dst_colorspace or src_color_range != dst_color_range: with nogil: - # Casts for const-ness, because Cython isn't expressive enough. ret = lib.sws_getColorspaceDetails( self.ptr, @@ -171,7 +167,6 @@ cdef class VideoReformatter: err_check(ret) with nogil: - # Grab the coefficients for the requested transforms. # The inv_table brings us to linear, and `tbl` to the new space. if src_colorspace != lib.SWS_CS_DEFAULT: diff --git a/av/video/stream.pyx b/av/video/stream.pyx index 9f4bacc87..08949be2e 100644 --- a/av/video/stream.pyx +++ b/av/video/stream.pyx @@ -1,12 +1,7 @@ cdef class VideoStream(Stream): - def __repr__(self): - return "" % ( - self.__class__.__name__, - self.index, - self.name, - self.format.name if self.format else None, - self.codec_context.width, - self.codec_context.height, - id(self), + return ( + f"" )