Dummy video device - v4l2loopback - webRTC
Solution 1
there are two things:
you need a recent enough
v4l2loopback
module, IIRC you have to use at least0.7.1
$ dmesg | grep v4l2loopback
[0000123.456] v4l2loopback driver version 0.8.0 loaded
the
v4l2loopback
-device will only appear as a proper webcam, if some (other) application is writing video data to it. e.g.gst-launch videotestsrc ! v4l2sink device=/dev/video0
Solution 2
I was able to get this to work using ffmpeg. This was the command I used:
ffmpeg -re -f lavfi -i "movie=my_video_file.mp4" -f v4l2 /dev/video0
After doing that, I was able to access this virtual webcam, which was looping a video file infinitely, from my WebRTC app.
![Al3](https://i.stack.imgur.com/4e8w4.jpg?s=256&g=1)
Al3
Updated on June 20, 2022Comments
-
Al3 about 2 years
I need to play multiple video for test a video server. I'm using lubuntu 14.04 and have installed V4l2loopback to make the device file ( /dev/videoN )
I am using mplayer to play video from this device as described mplayer cam
I have done the modify to the source code and successfully played the video and viewed with xawtv and with flashplayer (on firefox 28). I have tried to view with webRtc but it can't work.
Do you have some idea to do this? There is some particular pixelformat to define in examples/yuv4mpeg_to_v4l2.c ?
.....
I'm trying to find the problem using direct access to the resource with this script:
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Test rtc</title> <script type="text/javascript" charset="utf-8"> navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia ); var constraints = { audio: true, video:true, video: { mandatory: { minWidth: 640, minHeight: 360 } } }; if( navigator.getUserMedia ) { navigator.getUserMedia( // constraints constraints , // successCallback function(localMediaStream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(localMediaStream); video.play(); console.log( video ); console.log( localMediaStream ); }, // errorCallback function(err) { console.log("The following error occured: " + err); } ); } else { console.log("getUserMedia not supported"); } </script> </head> <body> <video> </body> </html>
The video constraingts are take from mplayer output:
VIDEO: 640x360 25.000 fps 555.0 kbps (69.4 kB/s) [swscaler @ 0x7f83633f3640]BICUBIC scaler, from yuv420p to yuv420p using MMXEXT VO: [yuv4mpeg] 480x360 => 640x360 Planar YV12
But the problem persists: "The following error occured: Starting video failed"..
The video is correctly played and visible both with xawtv and with flashplayer.