diff --git a/av/video/frame.pyx b/av/video/frame.pyx index 6c8b247b8..9498938e6 100644 --- a/av/video/frame.pyx +++ b/av/video/frame.pyx @@ -381,24 +381,24 @@ cdef class VideoFrame(Frame): return frame @staticmethod - def from_numpy_buffer(array, format='rgb24'): - if format in ["rgb24", "bgr24"]: + def from_numpy_buffer(array, format="rgb24"): + if format in ("rgb24", "bgr24"): check_ndarray(array, 'uint8', 3) check_ndarray_shape(array, array.shape[2] == 3) height, width = array.shape[:2] - elif format in ('gray', 'gray8', 'rgb8', 'bgr8'): - check_ndarray(array, 'uint8', 2) + elif format in ("gray", "gray8", "rgb8", "bgr8"): + check_ndarray(array, "uint8", 2) height, width = array.shape[:2] - elif format in ["yuv420p", "yuvj420p", "nv12"]: - check_ndarray(array, 'uint8', 2) + elif format in ("yuv420p", "yuvj420p", "nv12"): + check_ndarray(array, "uint8", 2) check_ndarray_shape(array, array.shape[0] % 3 == 0) check_ndarray_shape(array, array.shape[1] % 2 == 0) height, width = array.shape[:2] height = height // 6 * 4 else: - raise ValueError('Conversion from numpy array with format `%s` is not yet supported' % format) + raise ValueError(f"Conversion from numpy array with format `{format}` is not yet supported") - if not array.flags['C_CONTIGUOUS']: + if not array.flags["C_CONTIGUOUS"]: raise ValueError("provided array must be C_CONTIGUOUS") frame = alloc_video_frame() diff --git a/av/video/plane.pyx b/av/video/plane.pyx index 3d0a523b0..de8959e67 100644 --- a/av/video/plane.pyx +++ b/av/video/plane.pyx @@ -2,11 +2,9 @@ from av.video.frame cimport VideoFrame cdef class VideoPlane(Plane): - def __cinit__(self, VideoFrame frame, int index): - # The palette plane has no associated component or linesize; set fields manually - if frame.format.name == 'pal8' and index == 1: + if frame.format.name == "pal8" and index == 1: self.width = 256 self.height = 1 self.buffer_size = 256 * 4 @@ -19,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("could not find plane %d of %r" % (index, frame.format)) # Sometimes, linesize is negative (and that is meaningful). We are only # insisting that the buffer size be based on the extent of linesize, and @@ -43,7 +41,7 @@ cdef class YUVPlanes(VideoPlane): def __cinit__(self, VideoFrame frame, int index): if index != 0: raise RuntimeError("YUVPlanes only supports index 0") - if frame.format.name not in ['yuvj420p', 'yuv420p']: + if frame.format.name not in ("yuvj420p", "yuv420p"): raise RuntimeError("YUVPlane only supports yuv420p and yuvj420p") if frame.ptr.linesize[0] < 0: raise RuntimeError("YUVPlane only supports positive linesize")