How to write to v4l2 virtual device

I can’t seem to find an authoritative guide on how to write to a v4l2 virtual device in a manner that permits other applications to recognize the device as a video output.

gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video2
will permit google meet to use /dev/video2 “Virtual Camera 1” as a video input device, as will
ffmpeg -f v4l2 -i /dev/video0 -f v4l2 /dev/video2

I cannot, however find the correct incantation to permit a python script using the opencv module to perform in a similar manner. I am starting with a passthrough test script:

import cv2

cap = cv2.VideoCapture(‘/dev/video0’)

if not cap.isOpened():
print(“Error: Could not open video device.”)
exit()

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

fourcc = cv2.VideoWriter_fourcc(*‘YUYV’) # YUYV format for v4l2loopback
out = cv2.VideoWriter(‘/dev/video2’, fourcc, 30.0, (640,480))

while True:
ret, frame = cap.read()
if not ret:
print(“Error: Could not read frame.”)
break

out.write(frame)
cv2.imshow(‘Frame’, frame)

if cv2.waitKey(1) & 0xFF == ord(‘1’):
break

cap.release()
out.release()
cv2.destroyAllWindows()