2

I have created following script I've been using on Arch Linux to stream the camera feed to 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)"

Since I've switched to NixOS, it stopped working with following error.

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

I've tried to capture frame using gphoto2 and it successfully captures one frame.

gphoto2 --capture-movie=1

Applications

❯ 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 ];

Why does it say v4l2 is not suitable?

Destroy666
  • 5,299
  • 7
  • 16
  • 35
s1n7ax
  • 182
  • 9
  • 1
    Start by upgrading your software. ffmpeg is definitely outdated as 6 exists. Install the `full` version too for the biggest coverage: https://search.nixos.org/packages?channel=23.05&show=ffmpeg_6-full&from=0&size=50&sort=relevance&type=packages&query=ffmpeg – Destroy666 Aug 14 '23 at 21:12
  • If that doesn't help, show the whole output of `ffmpeg` and only the `v4l2` part of `ffmpeg -formats` in the question. – Destroy666 Aug 14 '23 at 21:20
  • 1
    @Destroy666 worked. Thanks. Do you want to add this an answer – s1n7ax Aug 15 '23 at 05:04
  • @Destroy666 Patch 5.1.3 was technically released after 6.0 – FFmpegEnthusiast Aug 23 '23 at 17:54
  • @FFmpegEnthusiast nothing new - older major versions can get newer minor bugfixes than some nwer major versions. But when it comes to wanting more features, you have to go for newer. – Destroy666 Aug 23 '23 at 18:03
  • @Destroy666 You're correct but I was saying technically – FFmpegEnthusiast Aug 23 '23 at 19:34

1 Answers1

1

Firstly, remember to always keep your software up-to-date, unless you require a specific version for a known reason like a bug in a newer one. ffmpeg is on version 6.x right now and NixOS has built packages for it.

Secondly, for ffmpeg, it's always good to install the full build. One also exists for NixOS. You can be (almost) sure with that that you're not missing out on any optional dependencies, except for e.g. cases when they're only available for specific systems. Here v4l2 is indeed optional, which can be seen in the source of the package.

Destroy666
  • 5,299
  • 7
  • 16
  • 35