Send frames to a virtual camera
Low maintenance activity. Last release 10 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install pyvirtualcampyvirtualcam
pyvirtualcam sends frames to a virtual camera from Python.
Usage
import colorsys
import numpy as np
import pyvirtualcam
with pyvirtualcam.Camera(width=1280, height=720, fps=20) as cam:
print(f'Using virtual camera: {cam.device}')
frame = np.zeros((cam.height, cam.width, 3), np.uint8) # RGB
while True:
h, s, v = (cam.frames_sent % 100) / 100, 1.0, 1.0
r, g, b = colorsys.hsv_to_rgb(h, s, v)
frame[:] = (r * 255, g * 255, b * 255)
cam.send(frame)
cam.sleep_until_next_frame()
pyvirtualcam uses the first available virtual camera it finds (see later section).
For more examples, including using different pixel formats like BGR, or selecting a specific camera device, check out the examples/ folder.
See also the API Documentation.
Installation
This package works on Windows, macOS, and Linux. Install it from PyPI with:
pip install pyvirtualcam
pyvirtualcam relies on existing virtual cameras which have to be installed first. See the next section for details.
Supported virtual cameras
Windows: OBS
OBS includes a built-in virtual camera for Windows (since 26.0).
To use the OBS virtual camera, simply install OBS.
Note that OBS provides a single camera instance only, so it is not possible to send frames from Python to the built-in OBS virtual camera, capture the camera in OBS, mix it with other content, and output it again to OBS' built-in virtual camera. To achieve such a workflow, use another virtual camera from Python (like Unity Capture) so that OBS' built-in virtual camera is free for use in OBS.
Windows: Unity Capture
Unity Capture provides a virtual camera originally meant for streaming Unity games. Compared to most other virtual cameras it supports RGBA frames (frames with transparency) which in turn can be captured in OBS for further processing.