Skip to content

Instantly share code, notes, and snippets.

@mtn
Created May 8, 2020 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtn/086dfd0ed7d673690ce5c12983c43634 to your computer and use it in GitHub Desktop.
Save mtn/086dfd0ed7d673690ce5c12983c43634 to your computer and use it in GitHub Desktop.
>>> import numpy as np
>>> from av import VideoFrame
>>> a = np.zeros((3,3,3))
>>> a[:,:,2] = 255
>>> a = a.astype(np.uint8)
>>> a
array([[[  0,   0, 255],
        [  0,   0, 255],
        [  0,   0, 255]],

       [[  0,   0, 255],
        [  0,   0, 255],
        [  0,   0, 255]],

       [[  0,   0, 255],
        [  0,   0, 255],
        [  0,   0, 255]]], dtype=uint8)
>>> video_frame = VideoFrame.from_ndarray(a, format="bgr24")
>>> video_frame.reformat(format="yuv420p").reformat(format="bgr24").to_ndarray()
array([[[  0,   0, 253],
        [  0, 230,   0],
        [  0, 136,   0]],

       [[  0,   0, 253],
        [  0, 230,   0],
        [  0, 136,   0]],

       [[  0,   0, 253],
        [  0, 230,   0],
        [  0, 136,   0]]], dtype=uint8)
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment