jacksonliam / mjpg-streamer

Fork of http://sourceforge.net/projects/mjpg-streamer/
3.01k stars 1.23k forks source link

Add support for v4l2loopback device #346

Open wuhanstudio opened 2 years ago

wuhanstudio commented 2 years ago

Hi,

In continuation to the conversation at https://github.com/jacksonliam/mjpg-streamer/pull/280.

This PR adds support for v4l2loopback devices simply by changing NB_BUFFER to 1. It seems like the reason input_uvc does not work is because it uses 4 buffers, while v4l2loopback devices only support 1.

This PR is definitely not a good solution, but a simple workaround. It's much better if we can add a parameter for the number of buffers. What do you think?

I agree with you that:

It does seem strange to create a whole other plugin to get around some bug or missing implementation in v4l2loopback

To reproduce, first, we create two virtual cameras (v4l2loopback devices) from one HD camera:

$ sudo modprobe v4l2loopback video_nr="40,41"
$ git clone https://github.com/wuhanstudio/v4l2loop_clone
$ cd v4l2loop_clone && make
$  ./v4l2loop_clone /dev/video0 /dev/video40 /dev/video41

Now, we can stream the video using mjpg-streamer:

$ git clone https://github.com/wuhanstudio/mjpg-streamer
$ cd mjpg-streamer/mjpg-streamer-experimental/ && make
$ ./mjpg_streamer -i "./input_uvc.so  -r 640x480 -d /dev/video40"  -o "./output_http.so -w ./www"
jacksonliam commented 2 years ago

Interesting discovery. I wonder if there's any way to query the v4l2 device to find out how many buffers it supports. One seems a touch low though. I'd have thought you'd want to double buffer minimum.

wuhanstudio commented 2 years ago

Interesting discovery. I wonder if there's any way to query the v4l2 device to find out how many buffers it supports. One seems a touch low though. I'd have thought you'd want to double buffer minimum.

The max number of buffers for v4l2loopback is 2 which is hard-coded according to:

#define V4L2LOOPBACK_DEFAULT_MAX_BUFFERS 2

https://github.com/umlaeute/v4l2loopback/blob/2199283ee936b9930038552b7a0890ec1736e7a2/v4l2loopback.c#L216