DSLR webcam and pipewire"">DSLR webcam and pipewire
Berend De Schouwer
tl;dr
It used to be possible to use a DSLR as a webcam, or in OBS, on Linux, and with the move to pipewire this broke.
Here’s the code to make it work again:
gst-launch-1.0 \
clockselect \
v4l2src \
device=/dev/video0 \
! queue ! videoconvert \
! pipewiresink mode=provide stream-properties="properties,media.class=Video/Source,media.role=Camera" \
client-name=DSLR
background
On Linux, you can use your DSLR as a webcam, and have any application use it. What you need is: * gphoto2 * ffmpeg * v4l2loopback (kernel module)
The recipe can be slightly different based on camera functionality like frame rate and resolution, but it basically follows
gphoto2 --set-config liveviewsize=2 \
--stdout --capture-movie \
| ffmpeg -i - \
-re \
-vcodec rawvideo \
-pix_fmt yuv420p \
-threads 2 \
-f v4l2 /dev/video0
Most DSLRs are supported.
With the move to pipewire, another step is needed. This blog post describes that step.
You may need to change:
- liveviewsize=2
- Different cameras will have different options
- -re
- -re should make ffmpeg match the native framerate, which may save CPU cycles
clock bug
The output of the gst command should have an advancing clock. If the
clock remains stuck on 00:00:00, you will need to add clockselect
to the gst-launch
command at the top.
This is related to Pipewire Regressin 4389
when
Right now, December 2024. Firefox, OBS and Chrome are moving to pipewire. The move has happened in some distributions, and is in the process in others.
firefox
Look in about:config
for media.webrtc.camera.allow-pipewire
chrome
Look in chrome://flags
for Pipewire Camera Support
who
pipewire aims to improve the handling of audio and video on Linux, and it’s pretty good at that.
You’ll need version 1.2.6 or later for this to work. Look for
libpw-v4l2.so
.
what
A DSLR camera, attached via USB, that you used to use using gphoto2
and
v4l2loopback
where
wpctl status
Look for a section like:
Video
├─ Devices:
│ 56. ...
│
├─ Sinks:
│
├─ Sources:
│ * 64. USB2.0 FHD UVC WebCam (V4L2)
│ 93. DSLR
You want your DSLR to show up under Sources
.
You can then get more information using pw-cli info 93
why
Update to pipewire. It really is better.
how
After running gphoto2
the way you normally do, run the command
at the top. You can name your DSLR something else if you like.
Test it using wpctl status
and pw-cli info