Skip to content

Conversation

caffeinism
Copy link
Contributor

@caffeinism caffeinism commented Aug 30, 2025

I'm writing a PR for this issue. I think LLMs are dumb, but I think I'm dumber when it comes to Cython and libav, so please understand that I wrote the code as a dumb-squared combination. I really want to use this feature and hope you'll consider this a draft.

import av
import av.filter
import numpy as np

w = 1024
h = 1024

x = np.linspace(0, 255, w, dtype=np.uint8)
y = np.linspace(0, 255, h, dtype=np.uint8)
arr = np.zeros((h, w, 3), dtype=np.uint8)
arr[..., 0] = x[None, :]
arr[..., 1] = y[:, None]
arr[..., 2] = 128
frame = av.VideoFrame.from_ndarray(arr, format="rgb24")

graph = av.filter.Graph()

src = graph.add_buffer(template=frame)
scale = graph.add("scale", args=f"w={512}:h={512}")
sink = graph.add("buffersink")

src.link_to(scale)
scale.link_to(sink)
graph.configure()

src.push(frame)
out1 = sink.pull()
print(f"1st: {out1.width}x{out1.height}")

scale.process_command("width", "512")
scale.process_command("height", "256")

src.push(frame)
out2 = sink.pull()
print(f"2nd: {out2.width}x{out2.height}")

frame:
image

out1:
image

out2:
image

import av
import av.filter
import numpy as np

w = 1024
h = 1024

x = np.linspace(0, 255, w, dtype=np.uint8)
y = np.linspace(0, 255, h, dtype=np.uint8)
arr = np.zeros((h, w, 3), dtype=np.uint8)
arr[..., 0] = x[None, :]
arr[..., 1] = y[:, None]
arr[..., 2] = 128
frame = av.VideoFrame.from_ndarray(arr, format="rgb24")
square = av.VideoFrame.from_ndarray(np.zeros((256, 256, 3), dtype=np.uint8), format="rgb24")
frame.pts = square.pts = None

graph = av.filter.Graph()

src = graph.add_buffer(template=frame)
dst = graph.add_buffer(template=square)
overlay = graph.add("overlay", args=f"x={256}:y={256}")
sink = graph.add("buffersink")

src.link_to(overlay, input_idx=0)
dst.link_to(overlay, input_idx=1)
overlay.link_to(sink)
graph.configure()


src.push(frame)
dst.push(square)
out1 = sink.pull()

overlay.process_command("x", "512")
overlay.process_command("y", "512")

src.push(frame)
dst.push(square)
out2 = sink.pull()

out1
image

out2
image

@WyattBlue WyattBlue merged commit 7de657a into PyAV-Org:main Aug 30, 2025
5 checks passed
@caffeinism caffeinism deleted the process-command branch August 31, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants