• Stars
    star
    330
  • Rank 127,657 (Top 3 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎥 Send frames to a virtual camera from Python

pyvirtualcam

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.

To use the Unity Capture virtual camera, follow the installation instructions on the project site.

macOS: OBS

OBS includes a built-in virtual camera for macOS (since 26.1).

NOTE: Starting with pyvirtualcam 0.10, only OBS 28 is supported. Install an older version if you need OBS 26 / 27 support.

To use the OBS virtual camera, follow these one-time setup steps:

  • Install OBS.
  • Start OBS.
  • Click "Start Virtual Camera" (bottom right), then "Stop Virtual Camera".
  • Close OBS.

Note that OBS provides a single camera instance only, so it is not possible to send frames from Python, capture the camera in OBS, mix it with other content, and output it again as virtual camera.

Linux: v4l2loopback

pyvirtualcam uses v4l2loopback virtual cameras on Linux.

To create a v4l2loopback virtual camera on Ubuntu, run the following:

sudo apt install v4l2loopback-dkms
sudo modprobe v4l2loopback devices=1

For further information, see the v4l2loopback documentation.

Build from source

Linux/macOS

git clone https://github.com/letmaik/pyvirtualcam --recursive
cd pyvirtualcam
pip install .

Windows

These instructions are experimental and support is not provided for them. Typically, there should be no need to build manually since wheels are hosted on PyPI.

You need to have Visual Studio installed to build pyvirtualcam.

In a PowerShell window:

$env:USE_CONDA = '1'
$env:PYTHON_VERSION = '3.7'
$env:PYTHON_ARCH = '64'
$env:NUMPY_VERSION = '1.14'
git clone https://github.com/letmaik/pyvirtualcam --recursive
cd pyvirtualcam
powershell .github/scripts/build-windows.ps1

The above will download all build dependencies (including a Python installation) and is fully configured through the four environment variables. Set USE_CONDA = '0' to build within an existing Python environment.

More Repositories

1

rawpy

📷 RAW image processing for Python, a wrapper for libraw
Cython
481
star
2

lensfunpy

📷 Lens distortion correction for Python, a wrapper for lensfun
Cython
127
star
3

vscode-git-tree-compare

🎄 VS Code extension for comparing the git working tree against a branch, tag, or commit, displayed as folder tree
TypeScript
48
star
4

node-virtualcam

🎥 Send frames to a virtual camera from Node.js
C
43
star
5

monadiccp

Monadic Constraint Programming framework
Haskell
26
star
6

evolutionary-container-loading

Container loading with evolutionary algorithms in Scala
Scala
20
star
7

rawpy-notebooks

A collection of Jupyter notebooks using rawpy
Jupyter Notebook
19
star
8

xndarray

▦ Multidimensional arrays with semantics in JavaScript
JavaScript
8
star
9

gwt-phantomjs-junit-runstyle

A GWT JUnit run style for local testing with PhantomJS
Java
7
star
10

pixelpitch

Lists current cameras with their physical pixel sizes (pixel pitch)
Python
5
star
11

hungrymonkey

🎮 The Hungry Monkey Game
JavaScript
5
star
12

meeting-backgrounds

🖼️ Download and manage meeting background collections.
Python
5
star
13

PSExercise

▶️ YouTube videos on a schedule
PowerShell
4
star
14

chip8

🕹 CHIP-8 emulator written in AssemblyScript
TypeScript
4
star
15

crowfood

Creates dependency files from C/C++ code for creating dependency graphs with snakefood
Python
3
star
16

pixelart

🎨 My pixel art
3
star
17

valijson-wasm

valijson in the browser
HTML
2
star
18

playingcards-rooms

🎲 Custom rooms for playingcards.io
2
star
19

hungrypuffin

🎮 The Hungry Puffin Game
TypeScript
2
star
20

leafy

🍁 A minigame about leaves
C#
2
star
21

profviewer

🩺 Online viewer for runtime profiles.
JavaScript
2
star
22

gwt-webdriver-junit-runstyle

A GWT JUnit run style for remote testing via WebDriver's JSON over HTTP protocol
Java
1
star
23

exhaust

🌌 Exhaustively enumerate a combinatorial space
Python
1
star
24

ld-trace

ld --trace-symbol, but better.
Python
1
star
25

vscode-metalevel-references

VS Code extension that adds "Find All References" to the file and folder level
TypeScript
1
star
26

lensfunx

Experiments with lensfun
Python
1
star
27

rna-and-adp-wiki

A wiki about RNA folding basics and ADP implementations.
1
star
28

sweetdreams-netvibes-theme

Adaptation of iGoogle's "Sweet Dreams" theme for netvibes
1
star