Created by: corco
Adds support for floating point RGB format.
Can be tested with this script:
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()