Skip to main content

Overview

The VirtualCameraDevice class represents a virtual camera that can be used to stream video frames into a Daily call. You can create a virtual camera device and write video frames to it programmatically.

Creation

Create a virtual camera device using the Daily.create_camera_device() static method:
from daily import Daily

camera = Daily.create_camera_device(
    device_name="my-virtual-camera",
    width=1280,
    height=720,
    color_format="RGBA"
)

Parameters

device_name
str
required
The name of the virtual camera device
width
int
required
The width of the video frames in pixels
height
int
required
The height of the video frames in pixels
color_format
str
default:"RGBA"
The color format of the video frames. Default is “RGBA”

Properties

name
str
The name of the virtual camera device
width
int
The width of the video frames in pixels
height
int
The height of the video frames in pixels
color_format
str
The color format of the video frames

Methods

write_frame()

Writes a single video frame to the virtual camera device.
camera.write_frame(frame)

Parameters

frame
bytes
required
The video frame data as bytes. The size should match width * height * bytes_per_pixel based on the color format

Returns

None

Example Usage

from daily import Daily, CallClient
import numpy as np

# Initialize Daily
Daily.init()

# Create a virtual camera device
camera = Daily.create_camera_device(
    device_name="my-camera",
    width=640,
    height=480,
    color_format="RGBA"
)

# Create a client and join a call
client = CallClient()
client.join("https://your-domain.daily.co/room")

# Update inputs to use the virtual camera
client.update_inputs({
    "camera": {
        "isEnabled": True,
        "settings": {
            "deviceId": camera.name
        }
    }
})

# Generate and write frames
while True:
    # Create a frame (example: solid color)
    frame = np.zeros((camera.height, camera.width, 4), dtype=np.uint8)
    frame[:, :] = [255, 0, 0, 255]  # Red color
    
    # Write the frame to the virtual camera
    camera.write_frame(frame.tobytes())
    
    # Control frame rate (e.g., 30 fps)
    time.sleep(1/30)

Build docs developers (and LLMs) love