Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added yuvj420p format for to_ndarray #583

Merged
merged 1 commit into from Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions av/video/frame.pyx
Expand Up @@ -236,7 +236,7 @@ cdef class VideoFrame(Frame):

import numpy as np

if frame.format.name == 'yuv420p':
if frame.format.name in ('yuv420p', 'yuvj420p'):
mikeboers marked this conversation as resolved.
Show resolved Hide resolved
assert frame.width % 2 == 0
assert frame.height % 2 == 0
return np.hstack((
Expand Down Expand Up @@ -277,7 +277,7 @@ cdef class VideoFrame(Frame):
"""
Construct a frame from a numpy array.
"""
if format == 'yuv420p':
if format in ('yuv420p', 'yuvj420p'):
assert array.dtype == 'uint8'
assert array.ndim == 2
assert array.shape[0] % 3 == 0
Expand Down
8 changes: 8 additions & 0 deletions tests/test_videoframe.py
Expand Up @@ -236,6 +236,14 @@ def test_ndarray_yuv420p_align(self):
self.assertEqual(frame.format.name, 'yuv420p')
self.assertTrue((frame.to_ndarray() == array).all())

def test_ndarray_yuvj420p(self):
array = numpy.random.randint(0, 256, size=(720, 640), dtype=numpy.uint8)
frame = VideoFrame.from_ndarray(array, format='yuvj420p')
self.assertEqual(frame.width, 640)
self.assertEqual(frame.height, 480)
self.assertEqual(frame.format.name, 'yuvj420p')
self.assertTrue((frame.to_ndarray() == array).all())

def test_ndarray_yuyv422(self):
array = numpy.random.randint(0, 256, size=(480, 640, 2), dtype=numpy.uint8)
frame = VideoFrame.from_ndarray(array, format='yuyv422')
Expand Down