Skip to content

Commit

Permalink
Use tuples and double qoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Dec 24, 2023
1 parent 635a6c5 commit 2f1bb1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 8 additions & 8 deletions av/video/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 3 additions & 5 deletions av/video/plane.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 2f1bb1d

Please sign in to comment.