Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4l2 output options #33

Closed
acidkewpie opened this issue Oct 26, 2023 · 10 comments
Closed

v4l2 output options #33

acidkewpie opened this issue Oct 26, 2023 · 10 comments

Comments

@acidkewpie
Copy link

Is there any way to leverage the impressive performance benefits with a v4l2loopback output? I see it's not built in (yet?) like wf-recorder has, but even past that, any way to pipe to ffmpeg or such? Any plans?

@russelltg
Copy link
Owner

Yeah, that's possible. It might work by using the file output and format options to feed raw video into v4l2 loopback. It would likely introduce a buffer copy which would negate some of the performance wins of this program. I'll give that a test sometime soon.

If v4l2loopback supports feeding h264 into it (I know v4l2 does, just unsure about v4l2loopback), then this could be quite efficient assuming the program that consumes it doesn't re encode it.

I assume you want this for zoom or something?

@russelltg
Copy link
Owner

russelltg commented Oct 30, 2023

After 4b8fc4e and b3f9945 this seems to be working well for me. Tested with

sudo modprobe v4l2loopback
wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video6

with https://mozilla.github.io/webrtc-landing/gum_test.html

It's just passing raw video to v4l2.

@russelltg
Copy link
Owner

You may also want to pass --encode-pixfmt=bgra if you want it to not be chroma subsampled

@acidkewpie
Copy link
Author

Ahh fantastic! I was only looking at the 0.1.0 release which didn't have those options. Rebuilding with git and things are looking good. Glad it was already there, you da man.

@acidkewpie
Copy link
Author

acidkewpie commented Nov 2, 2023

Close. so close... so I am trying to replicate

wf-recorder -g 5135,55 1920x1080 -f /dev/video10 -m v4l2 -c mjpeg -x yuv420p

I think that mpjeg is mandatory for zoom (despite my actual camera support h264 and getting my hopes up...) but I can't get mjpeg enabled in wl-screenrec.

$ wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video10 -g "5135,55 1920x1080" --encode-pixfmt yuv420p --ffmpeg-encoder mjpeg
Using output DP-1
failed to create encoder: Format video4linux2,v4l2 does not support MJPEG codec

or

$ wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video10 -g "5135,55 1920x1080" --codec mjpeg
error: invalid value 'mjpeg' for '--codec <CODEC>'
  [possible values: auto, avc, hevc, vp8, vp9]

I also have this running when the screen recorder is not, and it dishes out the mjpeg source just lovely.

ffmpeg -stream_loop -1 -re -i testcard.mp4 -f v4l2 -vcodec copy /dev/video10

@acidkewpie
Copy link
Author

Please disregard queries here, everything seems great now, potentially as your app is SO much more efficient than others that distortions happening previously with rawvideo aren't happening with wl-screenrec at all.

@punk-dev-robot
Copy link

@acidkewpie Could you please share what was the issue and the final command you used?

@russelltg
Copy link
Owner

I added an example that works for me with Zoom to the README

@acidkewpie
Copy link
Author

Yes, it was that simple for me in the end, bar a -g option. Wrapped it up in a systemd service and it's doing great now.

@punk-dev-robot
Copy link

punk-dev-robot commented Nov 27, 2023

So I have problems running version from git installed using cargo:

wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video8

Using output DP-3
hw flag is specified, but there's no known vaapi codec for RAWVIDEO. Using a generic encoder...
codec "rawvideo" does not advertize supported pixel formats, just using NV12. Pass --encode-pixfmt to suppress this warning
Opening libva device from DRM device /dev/dri/renderD128
[video4linux2,v4l2 @ 0x558ad6fd9a00] ioctl(VIDIOC_G_FMT): Invalid argument
thread 'main' panicked at src/main.rs:1352:29:
called `Result::unwrap()` on an `Err` value: ffmpeg::Error(22: Invalid argument)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I noticed the error about pixel format so added it:

wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video8 --encode-pixfmt yuv420p

sing output DP-3
hw flag is specified, but there's no known vaapi codec for RAWVIDEO. Using a generic encoder...
Opening libva device from DRM device /dev/dri/renderD128
[Parsed_scale_vaapi_1 @ 0x55a4bd42afc0] Hardware does not support output format yuv420p.
[Parsed_scale_vaapi_1 @ 0x55a4bd42afc0] Failed to configure output pad on Parsed_scale_vaapi_1
thread 'main' panicked at src/main.rs:1648:18:
called `Result::unwrap()` on an `Err` value: ffmpeg::Error(22: Invalid argument)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Now there is message about no support from hardware so I also disabled it:

wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video8 --encode-pixfmt yuv420p

Using output DP-3
Opening libva device from DRM device /dev/dri/renderD128
[Parsed_scale_vaapi_1 @ 0x55d27da9ec80] Hardware does not support output format yuv420p.
[Parsed_scale_vaapi_1 @ 0x55d27da9ec80] Failed to configure output pad on Parsed_scale_vaapi_1
thread 'main' panicked at src/main.rs:1648:18:
called `Result::unwrap()` on an `Err` value: ffmpeg::Error(22: Invalid argument)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm running hyprland on a laptop with new AMD Ryzen 7 7840U with integrated graphics.

Thank you for your time and help getting this far, I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants