我创建了以下脚本,用于在 Arch Linux 上将摄像头信号传输到 OBS
#!/usr/bin/env bash
set -euo pipefail
sudo modprobe v4l2loopback exclusive_caps=1 max_buffer=2
gphoto2 \
--stdout \
--set-config viewfinder=1 \
--capture-movie |
ffmpeg \
-i - \
-vcodec copy \
-threads 1 \
-f v4l2 \
"/dev/$(ls -1 /sys/devices/virtual/video4linux)"
自从我切换到 NixOS 后,它就停止工作并出现以下错误。
q --enable-libzimg --enable-zlib --disable-vulkan --disable-libglslang --disable-libsmbclient --disable-debug --enable-optimizations --disable-extra-warnings --disable-stripping
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
[mjpeg @ 0xe08300] Format mjpeg detected only with low score of 25, misdetection possible!
Input #0, mjpeg, from 'pipe:':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1024x576, 25 tbr, 1200k tbn
[NULL @ 0xe0af80] Requested output format 'v4l2' is not a suitable output format
/dev/video0: Invalid argument
我尝试使用 gphoto2 捕获帧并且成功捕获了一帧。
gphoto2 --capture-movie=1
应用
❯ nixos-version
23.05.2664.9034b46dc4c7 (Stoat)
❯ gphoto2 --version
gphoto2 2.5.28
❯ ffmpeg --version
ffmpeg version 5.1.3
boot.kernelModules = [ "v4l2loopback" ];
boot.extraModulePackages = [ pkgs.linuxPackages.v4l2loopback ];
为什么说 v4l2 不适合?