by evgpbfhnr · 4y ago · 0 comments
That might require you also remove the 'enabled = true' for the service, and make sure gphoto2 dies when the camera is unplugged?
Anyway, it was a nice read :)
services.udev.extraRules = ''
ACTION=="add", \
ATTR{idVendor}=="04a9", \
ATTR{idProduct}=="319a", \
ENV{SYSTEMD_WANTS}+="external_webcam.service", \
SUBSYSTEM=="usb", \
TAG+="systemd"
'';
systemd.services.external_webcam = {
enable = true;
script = ''
${pkgs.gphoto2}/bin/gphoto2 --stdout --capture-movie |
${pkgs.ffmpeg}/bin/ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video0
'';
wantedBy = ["multi-user.target"];
};
Worked first try! [1][1] https://gitlab.com/engmark/root/-/commit/ae59aad118e6effcf47...
sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d4-1\x2d4:1.0-sound-card1-controlC1.device
sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d1-1\x2d1:1.0-sound-card1-controlC1.device
notice the usb-`1-1:4` became `1-1:1`That makes BindsTo unpractical unless you're sure you'll always plug in the camera on the same port everytime, so it might not be best.
This made me look up how I'd do this if the needs arise, so I haven't tried, but `StopWhenUnneeded=true` in the service definition looks like it would stop it properly when the device "wanting" it is gone? cf. https://unix.stackexchange.com/questions/528803/systemd-does...
I learned something new :)