Skip to content

Commit d432bb2

Browse files
committed
Partially revert #1061
The YUV fastpath did not preserve the underlying byte-order, which causes issues for applications that rely on it.
1 parent 01a0cd8 commit d432bb2

File tree

3 files changed

+6
-37
lines changed

3 files changed

+6
-37
lines changed

av/video/frame.pyx

+6-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from av.enum cimport define_enum
66
from av.error cimport err_check
77
from av.utils cimport check_ndarray, check_ndarray_shape
88
from av.video.format cimport get_pix_fmt, get_video_format
9-
from av.video.plane cimport VideoPlane, YUVPlanes
9+
from av.video.plane cimport VideoPlane
1010

1111
import warnings
1212

@@ -303,21 +303,11 @@ cdef class VideoFrame(Frame):
303303
if frame.format.name in ("yuv420p", "yuvj420p"):
304304
assert frame.width % 2 == 0
305305
assert frame.height % 2 == 0
306-
# Fast path for the case that the entire YUV data is contiguous
307-
if (
308-
frame.planes[0].line_size == frame.planes[0].width and
309-
frame.planes[1].line_size == frame.planes[1].width and
310-
frame.planes[2].line_size == frame.planes[2].width
311-
):
312-
yuv_planes = YUVPlanes(frame, 0)
313-
return useful_array(yuv_planes).reshape(frame.height * 3 // 2, frame.width)
314-
else:
315-
# Otherwise, we need to copy the data through the use of np.hstack
316-
return np.hstack((
317-
useful_array(frame.planes[0]),
318-
useful_array(frame.planes[1]),
319-
useful_array(frame.planes[2])
320-
)).reshape(-1, frame.width)
306+
return np.hstack((
307+
useful_array(frame.planes[0]),
308+
useful_array(frame.planes[1]),
309+
useful_array(frame.planes[2])
310+
)).reshape(-1, frame.width)
321311
elif frame.format.name in ("yuv444p", "yuvj444p"):
322312
return np.hstack((
323313
useful_array(frame.planes[0]),

av/video/plane.pxd

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ cdef class VideoPlane(Plane):
66

77
cdef readonly size_t buffer_size
88
cdef readonly unsigned int width, height
9-
10-
11-
cdef class YUVPlanes(VideoPlane):
12-
pass

av/video/plane.pyx

-17
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,3 @@ cdef class VideoPlane(Plane):
3535
:type: int
3636
"""
3737
return self.frame.ptr.linesize[self.index]
38-
39-
40-
cdef class YUVPlanes(VideoPlane):
41-
def __cinit__(self, VideoFrame frame, int index):
42-
if index != 0:
43-
raise RuntimeError("YUVPlanes only supports index 0")
44-
if frame.format.name not in ("yuvj420p", "yuv420p"):
45-
raise RuntimeError("YUVPlane only supports yuv420p and yuvj420p")
46-
if frame.ptr.linesize[0] < 0:
47-
raise RuntimeError("YUVPlane only supports positive linesize")
48-
self.width = frame.width
49-
self.height = frame.height * 3 // 2
50-
self.buffer_size = self.height * abs(self.frame.ptr.linesize[0])
51-
self.frame = frame
52-
53-
cdef void* _buffer_ptr(self):
54-
return self.frame.ptr.extended_data[self.index]

0 commit comments

Comments
 (0)