Skip to content

linux-pipewire: Support MJPEG and H264 devices - #11371

Open
dimtpap wants to merge 1 commit into
obsproject:masterfrom
dimtpap:pipewire-camera-mjpeg-h264
Open

linux-pipewire: Support MJPEG and H264 devices#11371
dimtpap wants to merge 1 commit into
obsproject:masterfrom
dimtpap:pipewire-camera-mjpeg-h264

Conversation

@dimtpap

@dimtpap dimtpap commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

Description

With #9771, support was added for the Camera portal. However, code to support MJPEG and H264 devices didn't make it. This PR is basically the code that didn't land + some more to finish it up.

Similarly to the v4l2 plugin, it uses ffmpeg to decode the encoded streams.

Motivation and Context

MJPEG and H264 devices exist

Fixes #10180
Fixes #10994

How Has This Been Tested?

Connected an MJPEG webcam, added the source, video was coming through.
Raw formats worked when converting the MJPEG stream to a raw format using GStreamer.
I couldn't get H264 working with GStreamer, I'd appreciate if someone with an H264 device tested this.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch 2 times, most recently from e84c7b6 to 5d60e66 Compare October 8, 2024 18:11
@tytan652 tytan652 added Seeking Testers Build artifacts on CI platform/linux Categorizes issue or PR as affecting Linux specifically kind/feature Functionality or other elements that the project doesn't currently have. labels Oct 8, 2024
@GeorgesStavracas
GeorgesStavracas self-requested a review October 9, 2024 18:02
@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch 2 times, most recently from 397bd5a to dae65cb Compare October 16, 2024 09:47

@tytan652 tytan652 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After fighting with the non-specified flow of the source as it is (the format change is done only if the resolution and framerate is changed).
It looks functional as is at least for MJPEG, I can't test H264.

Comment thread plugins/linux-pipewire/formats.c Outdated
Comment thread plugins/linux-pipewire/pipewire.c Outdated
Comment thread plugins/linux-pipewire/pipewire.c Outdated
@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from dae65cb to a9699a1 Compare October 29, 2024 17:55
@mercuriete

mercuriete commented Nov 24, 2024

Copy link
Copy Markdown

tested this patch
https://patch-diff.githubusercontent.com/raw/obsproject/obs-studio/pull/11371.patch

on top of gentoo obs-studio-9999 package and it worked for me so far.

One little thing:
after open a webcam using MJPEG format like mine: Logitech HD Pro Webcam C920...
if you open Kamoso, Kamoso hangs.
But it works perfectly with chromium using google meets.

My use case is I can't change resolutions on pipewire-v4l2 so I use obs to change resolution and now video formats.

Now I can select 1080p@30fps.

I would recommend to test this patch using other software running at the same time.
At this point I only know "kamoso", "chromium" and "google-chrome"

Thank you, now I can go to work meetings using 1080p before it defaults to 640x480.

PS:
I would like to have someone porting qv4l2 to pipewire because after migrating to pipewire I lose all control of my webcam.
pw-v4l2 qv4l2 dont work.

@ChrisLane

Copy link
Copy Markdown

Just tested this for my use case in #10180 and it seems to be working very well for MJPEG!

Turns out my stream from gphoto2 was raw jpeg and not MJPEG though so I still needed to do some encoding to test

sink_name="DSLR"
pipewire_sink_props="p,node.description=$sink_name,node.name=$sink_name,media.role=Camera,media.class=Video/Source"

gphoto2 --stdout --capture-movie \
  | gst-launch-1.0 \
      fdsrc \
      ! jpegdec \
      ! jpegenc \
      ! jpegparse \
      ! queue \
      ! pipewiresink stream-properties="$pipewire_sink_props"

@ChrisLane

ChrisLane commented Feb 14, 2025

Copy link
Copy Markdown

@dimtpap would you mind resolving the merge conflicts please?

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from a9699a1 to b1edc1c Compare February 14, 2025 13:33
@dimtpap

dimtpap commented Feb 14, 2025

Copy link
Copy Markdown
Contributor Author

For the record I'm waiting for #11741 so I can finish and undraft this

@ChrisLane

ChrisLane commented Feb 18, 2025

Copy link
Copy Markdown

@dimtpap I've discovered that I sometimes get a segfault when switching between scene collections when a PipeWire MJPEG source is used.
I was unable to reproduce this with the video format set to YUYV422 on the same build.

Steps to reproduce:

  1. Install obs-studio-git modified with adding patch -Np1 < "$srcdir/11371.patch" to prepare() to apply this patch.
  2. From fresh OBS configs, create a second scene collection
  3. Add 1080p 30fps MJPEG Pipewire Video Capture Device to a scene
  4. Switch between the scenes repeatedly until a segfault occurs

I ran OBS in GDB and reproduced the segfault, here's the log for that:
https://gist.github.com/ChrisLane/547ec9570bb9c6f87b8ff5ce837d4ab6

Usually it says 'loop->recurse > 0' failed at ../pipewire/src/pipewire/thread-loop.c:425 pw_thread_loop_wait() just before the segfault but that doesn't seem to have happened in this case.

@ChrisLane

Copy link
Copy Markdown

@dimtpap there seems to be an issue with this when compiling and running against latest PipeWire.
The issue is described in a thread in this now closed PipeWire issue: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4643#note_2877800

Do you think this needs to be resolved in this PR?

@stephematician

Copy link
Copy Markdown
Contributor

I ran OBS in GDB and reproduced the segfault, here's the log for that: https://gist.github.com/ChrisLane/547ec9570bb9c6f87b8ff5ce837d4ab6

@ChrisLane - can you provide the results of where from GDB when the crash occurs?

@ChrisLane

Copy link
Copy Markdown

I ran OBS in GDB and reproduced the segfault, here's the log for that: gist.github.com/ChrisLane/547ec9570bb9c6f87b8ff5ce837d4ab6

@ChrisLane - can you provide the results of where from GDB when the crash occurs?

I don't think I'll have the time to provide that I'm afraid, I don't use the same set up any more.

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch 3 times, most recently from 3465208 to 3e4c838 Compare August 22, 2025 20:30
@dimtpap

dimtpap commented Aug 22, 2025

Copy link
Copy Markdown
Contributor Author

I've discovered that I sometimes get a segfault when switching between scene collections when a PipeWire MJPEG source is used. I was unable to reproduce this with the video format set to YUYV422 on the same build.

I got segfaults like this and in generally when destroying the source because the decoder was destroyed before the stream using it. This is now fixed.

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from 3e4c838 to b2cc8d0 Compare August 22, 2025 20:53
@dimtpap
dimtpap marked this pull request as ready for review August 22, 2025 21:11
@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from b2cc8d0 to a465a81 Compare August 23, 2025 08:12
@Stealcase

Copy link
Copy Markdown

I am very happy to see activity on this PR, because it would solve my Logitech HD Pro Webcam C920 being limited to 5fps and YUYV422 when trying to record in OBS through Video Capture Device (Pipewire) (BETA).

My impression is that C920s are very common in the wild after the pandemic, and the current experience of using them with OBS on Wayland has a ton of hiccups.

So I think this will increase the perceived stability/functionality of Pipewire and OBS on linux for a lot of the people who don't ever open Github.

@ManuLinares

Copy link
Copy Markdown

LGTM


Thanks, this patch works perfectly.

I'm using a Google Pixel 6a as s webcam via usb which now lets me pick

image

I'm on archlinux, obs-studio 32.0.2-1 plus this patch.
pipewire 1:1.4.9-1

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from a465a81 to fce7232 Compare January 15, 2026 19:20
@Novantric

Copy link
Copy Markdown

Let's get this reviewed!

@phileas0408

Copy link
Copy Markdown

can confirm it works perfectly with my cheap webcam and capture card
tested on flatpak

Comment thread plugins/linux-pipewire/pipewire.c
Comment thread plugins/linux-pipewire/video-decoder.c Outdated
Comment thread plugins/linux-pipewire/video-decoder.c Outdated
Comment thread plugins/linux-pipewire/video-decoder.h Outdated
@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch 2 times, most recently from 9d390f2 to cf556a2 Compare January 23, 2026 13:03
@dimtpap

dimtpap commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

Also note that while working on this I ran into the same problem described in #12779 and had to include that for this to work

@RytoEX

RytoEX commented Jan 23, 2026

Copy link
Copy Markdown
Member

Also note that while working on this I ran into the same problem described in #12779 and had to include that for this to work

#12779 has been merged.

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from cf556a2 to 8184969 Compare January 23, 2026 16:42
@rmader

rmader commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

Gentle ping here, just in case it fell through the cracks - otherwise sorry for the noise! :)

AFAICS all requested changes in the last review have been addressed and the MR has been rebased on top of #12779

@RytoEX @GeorgesStavracas when you have time, any chance you can have another look?

@dimtpap
dimtpap force-pushed the pipewire-camera-mjpeg-h264 branch from 8184969 to 519b09c Compare March 30, 2026 22:06
@Warchamp7 Warchamp7 added this to the OBS Studio 33.0 milestone Jul 6, 2026
@github-project-automation github-project-automation Bot moved this to Ready For Review in 33.0 Release Tracker Jul 30, 2026
@github-project-automation github-project-automation Bot moved this from Ready For Review to Requires Changes in 33.0 Release Tracker Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Functionality or other elements that the project doesn't currently have. platform/linux Categorizes issue or PR as affecting Linux specifically Seeking Testers Build artifacts on CI

Projects

Status: Requires Changes

Development

Successfully merging this pull request may close these issues.

Video Capture Device (PipeWire) only has YUYV422 Errors and no video with PipeWire Camera Portal