运行时错误:“v4l2loopback”后端:std::异常

运行时错误:“v4l2loopback”后端:std::异常

当我尝试执行以下代码时出现上述错误:

import pyvirtualcam
import numpy as np

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:
        frame[:] = cam.frames_sent % 255  # grayscale animation
        cam.send(frame)
        cam.sleep_until_next_frame()

我在树莓派上运行这个(内核版本:5.10,树莓派内核头版本是1:1.20210527-1)。

错误:

  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/pyvirtualcam/camera.py", line 219, in __init__
    raise RuntimeError('\n'.join(errors))
  RuntimeError: 'v4l2loopback' backend: std::exception

解决了:

v4l2loopback 由于某种原因崩溃,导致此问题,代码开头的以下几行修复了该问题。

 import os

 if "raspberrypi" in str(os.uname()):
            os.system("sudo modprobe -r v4l2loopback")
            os.system("sudo modprobe v4l2loopback")

相关内容