Use webcam in two applications under Linux simultaneously using v4l2loopback
For a recent project we wanted to be able to access the webcam trough Adobe Flash but at the same time record the stream as well with VLC. To do this I had to split the video from /dev/video0 to two virtual webcam devices. I used the v4l2loopback and ffmpeg to archieve this. First of all make sure you've installed ffmpeg apt-get install ffmpeg
Then load the v4l2loopback to enable two loopback devices modprobe v4l2loopback devices=2
And with the following line I duplicated the webcam. ffmpeg -f video4linux2 -s 800x600 -i /dev/video0 -codec copy -f v4l2 /dev/video1 \ -codec copy -f v4l2 /dev/video2
What it does is use the input of /dev/video and copy the stream to /dev/video1 and /dev/video2 Now you can select /dev/video1 in Flash and /dev/video2 in VLC or any other application you would like to use the webcam at same time. The line I used to record the webcam commandline in VLC is: cvlc v4l2://dev/video2 :v4l2-standard=ALL :input-slave=alsa://hw:1,0 :v4l2-chroma= \ :v4l2-input=0 :v4l2-audio-input=-1 :v4l2-width=800 :v4l2-height=600 \ :v4l2-aspect-ratio=16\:9 :v4l2-fps=0 :v4l2-use-libv4l2 :v4l2-tuner=0 \ :v4l2-tuner-frequency=-1 :v4l2-tuner-audio-mode=1 :no-v4l2-controls-reset \ :v4l2-brightness=-1 :v4l2-brightness-auto=-1 :v4l2-contrast=-1 \ :v4l2-saturation=-1 :v4l2-hue=-1 :v4l2-hue-auto=-1 :v4l2-white-balance-temperature=-1 \ :v4l2-auto-white-balance=-1 :v4l2-red-balance=-1 :v4l2-blue-balance=-1 :v4l2-gamma=-1 \ :v4l2-autogain=-1 :v4l2-gain=-1 :v4l2-sharpness=-1 :v4l2-chroma-gain=-1 \ :v4l2-chroma-gain-auto=-1 :v4l2-power-line-frequency=-1 :v4l2-backlight-compensation=-1 \ :v4l2-band-stop-filter=-1 :no-v4l2-hflip :no-v4l2-vflip :v4l2-rotate=-1 \ :v4l2-color-killer=-1 :v4l2-color-effect=-1 :v4l2-audio-volume=-1 \ :v4l2-audio-balance=-1 :no-v4l2-audio-mute :v4l2-audio-bass=-1 \ :v4l2-audio-treble=-1 :no-v4l2-audio-loudness :v4l2-set-ctrls= \ :live-caching=300 \ --sout="#transcode{vcodec=h264,vb=750,acodec=mp4a,ab=96,channels=2,samplerate=44100}:standard{access=file,dst="OUTPUTFILE.mp4"}"');
(No subject)