Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PyAV
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 37
    • Issues 37
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 26
    • Merge requests 26
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyAV
  • PyAV
  • Merge requests
  • !986

Add support in VideoFrame ndarray for gbrp formats

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/corco/ndarray-gbrp-int into main May 19, 2022
  • Overview 2
  • Commits 1
  • Pipelines 0
  • Changes 2

Created by: corco

This adds support for gbrp, gbrp10le, gbrp12le, gbrp14le, gbrp16le and their big-endian counterpart formats.

If this PR is ok, I will also add support in the near future for yuv444p, yuv422p and gbrp32f formats.

This can be tested using the following script (doesn't work for 14 & 16 bits)

import numpy as np
import av


WIDTH = 1920
HEIGHT = 1080
BIT_DEPTH = 12

if BIT_DEPTH == 8:
    pix_fmt = "gbrp"
    dtype = np.uint8
else:
    pix_fmt = f"gbrp{BIT_DEPTH}le"
    dtype = np.uint16

ocntnr = av.open("test.mp4", "w")
ovstrm = ocntnr.add_stream("av1")
ovstrm.width = WIDTH
ovstrm.height = HEIGHT
ovstrm.pix_fmt = pix_fmt

max = 2**BIT_DEPTH - 1
gradient = np.repeat(np.arange(WIDTH) / WIDTH, 3)
h = np.round(np.linspace(0, HEIGHT, 9, endpoint=True)).astype(np.uint32)

colours = [
    [max, max, max],  # White
    [max, 0, 0],  # Red
    [0, max, 0],  # Green
    [0, 0, max],  # Blue
    [max, max, 0],  # Yellow
    [max, 0, max],  # Magenta
    [0, max, max],  # Cyan
    [0, 0, 0],  # Black
]

array = np.empty((HEIGHT, WIDTH, 3), dtype=dtype)
for idx, colour in enumerate(colours):
    array[h[idx] : h[idx + 1], :, :] = (gradient * np.tile(np.array(colour, dtype=dtype), WIDTH)).reshape(WIDTH, -1)

frame = av.VideoFrame.from_ndarray(array, pix_fmt)
for p in ovstrm.encode(frame):
    ocntnr.mux(p)

for p in ovstrm.encode():
    ocntnr.mux(p)

ocntnr.close()
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/corco/ndarray-gbrp-int