raymanfx / libv4l-rs

Video4Linux2 bindings for Rust
MIT License
145 stars 62 forks source link

Fix example forward video #22

Closed mijoharas closed 3 years ago

mijoharas commented 3 years ago

Hi!

These two examples didn't work for me using v4l2loopback. I figured out that this would work after looking at your stream_forward_mmap.rs example.

The error message I would get is:

thread 'main' panicked at 'Failed to set format of output device: Os { code: 16, kind: Other, message: "Device or resource busy" }', examples/forward_frame.rs:60:10

Incidentally, when I try the example from stream_forward_mmap it appears to work correctly, but if I try and play it with ffplay I'm not able to see anything.

I realise this example is quite new, should it be working?

(if it helps, the output I get after running stream_forward from running ffplay /dev/video2:

ffplay /dev/video2  
ffplay version n4.3.1 Copyright (c) 2003-2020 the FFmpeg developers
  built with gcc 10.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
    nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0   

and then hanging)

raymanfx commented 3 years ago

Hi, can you check out the next branch? I think I ran into a similar issue on Fedora 33, but it was actually the buggy v4l2loopback module to blame.

The "fix" or workaround I found is here: https://github.com/raymanfx/libv4l-rs/blob/next/examples/stream_forward_mmap.rs#L90.

raymanfx commented 3 years ago

Sorry, I got confused for a sec here. The master branch already has the "fix", but not for the two examples you fixed here.

I'll have a look at this soon - but I can say that the current code was tested on Fedora 33 with the latest v4l2loopback master branch and works fine, even using ffplay.

mijoharas commented 3 years ago

Hey, yeah, I just copied the fix from that example to here.

It'd be good to understand what's not working about the stream_forward_mmap file for me. I'll update if I dig in further and figure it out, but as I have something working now, I'm not sure if I will.

Thanks for the repo and everything, and merry christmas!

mijoharas commented 3 years ago

Ok, I got curious. 67ace347ce77718702c45557fce4846bdd9141d2 has a working (for me) stream implementation. 8586075 doesn't work for me.

raymanfx commented 3 years ago

That's most curious indeed. It would certainly help if you could find out what exactly breaks it for you. As I said, I will have a look at this myself, but that might take some more days.

Anyways, thanks for putting in the effort!

raymanfx commented 3 years ago

I consider these examples deprecated and will remove them. The stream_* examples should cover the same usecases.

raymanfx commented 3 years ago

Can you open an issue about the non-working v4l2loopback & ffplay setup? Please describe what you've tried so far, which versions you used etc etc. Thanks!

raymanfx commented 3 years ago

I just ran some tests on Fedora 33 and was able to reproduce your issue. Could you please check out this fix: https://github.com/raymanfx/libv4l-rs/commit/73fe21769c3c5c5b0950f0f6614cdda2aa255cc0?

My v4l2loopback + ffplay setup works again for webcam forwarding using that patch.