Skip to content

Instantly share code, notes, and snippets.

@smunix
Forked from TheSirC/v4l2.nix
Created September 3, 2021 00:10
Show Gist options
  • Save smunix/dd97501e9ac5f55aed57c54d2762a19a to your computer and use it in GitHub Desktop.
Save smunix/dd97501e9ac5f55aed57c54d2762a19a to your computer and use it in GitHub Desktop.
My Nix module to work with v4l2loopback
{ lib, config, pkgs, ... }:
with lib;
{
options.v4l2 = mkEnableOption "Enable the confguration to use the reflex as a webcam";
config = mkIf config.v4l2 {
# 20.03: v4l2loopback 0.12.5 is required for kernel >= 5.5
# https://github.com/umlaeute/v4l2loopback/issues/257
# Extra kernel modules
boot.extraModulePackages = with unstable; [
config.boot.kernelPackages.v4l2loopback
];
# Register a v4l2loopback device at boot
boot.kernelModules = [
"v4l2loopback"
];
boot.extraModprobeConfig = ''
options v4l2loopback exclusive_caps=1 video_nr=9 card_label=a7III
'';
};
}
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p gphoto2 ffmpeg zoom-us
set -euo pipefail
function connect-camera() {
gphoto2 --stdout --capture-movie 2> ~/tmp/camera.log | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video9 > /dev/null 2> ~/tmp/encoding-err.log &
PID_CAM=$!
}
function main() {
connect-camera &&\
read -n 1 -s -r -p "Press any key to continue" &&\
zoom-us 2> ~/tmp/zoom-output.log &&\
kill -KILL $PID_CAM
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment