Following on from the previous webcam posts, I decided to see if the Pi has enough grunt to stream 2 webcams at once.
The USB driver for the Pi at the moment isn’t quite up to the task at the moment, but I can get the 2 streaming at low resolutions for hours at a time at the moment.
I am still using the original ffmpeg that I compiled back from the first post.
I modified the ffserver.conf so that it would accept 2 streams of input rather than just one.
The following stanza is duplicated
<feed webcam.ffm>
file /tmp/webcam.ffm
FileMaxSize 20M
</Feed>
Like so – I added the number to the end to identify which webcam was which.
<Feed webcam0.ffm>
file /tmp/webcam0.ffm
FileMaxSize 20M
</Feed>
<Feed webcam1.ffm>
file /tmp/webcam1.ffm
FileMaxSize 20M
</Feed>
Then, the Stream stanzas are also duplicated.
These will be the addresses that are accessed to view the stream.
This is also where the bitrate, framerate and quality settings are defined.
<Stream webcam0.mjpeg>
Feed webcam0.ffm
Format mjpeg
VideoSize 320x240
VideoFrameRate 4
VideoBitRate 10000
VideoQMin 1
VideoQMax 10
</Stream>
<Stream webcam1.mjpeg>
Feed webcam1.ffm
Format mjpeg
VideoSize 320x240
VideoFrameRate 4
VideoBitRate 10000
VideoQMin 1
VideoQMax 10
</Stream>
After the ffserver.conf file is modified, ffmpeg will need to be run twice. Once for each webcam.
The command is the same, except for changing the input file at the end.
ffmpeg -loglevel info -r 4 -s 160x120 -f video4linux2 -i /dev/video0 http://localhost/webcam0.ffm
ffmpeg -loglevel info -r 4 -s 160x120 -f video4linux2 -i /dev/video1 http://localhost/webcam1.ffm
Running those 2 commands will then start streaming both webcams into ffserver, which will in turn make the streams accessible via a web browser.
Thank you for writing this tutorial! I’m looking to do exactly this for 3d image transmission for a robotics project and was wondering what brand webcams you used.
No problems 🙂 Thanks for reading 🙂
I’m just using some generic webcams from ebay / dealextreme.
They work reasonably well for the price, but if you want something higher res I would recommend the logitechs that people have had some success using.
Though the higher resolution will take it’s toll on the Pi’s CPU
Hello, I wan’t to stream 2 Logitech c270 camera at high resolution using my RPI 3. Raspbian Jessei is the os I am using can you help me? And I want to stream the audio from the microphone also. This is for making a VR system for my new robotic project.
Unfortunately I’ve never done 2 with audio on a Pi before. You could try with ffmpeg and see how you go?
Hello,
First things first, thanks for the great tutorial!
So… I`ve set /etc/ffserver.conf as per part1 and modded it like you did here, but when I run either
ffmpeg -loglevel info -r 4 -s 160×120 -f video4linux2 -i /dev/video0
or
ffmpeg -loglevel info -r 4 -s 160×120 -f video4linux2 -i /dev/video1
I keep getting “At least one output file must be specified”
Any clues on how to solve that?
Btw, I`m running it on Raspbian Jessie.
Thanks in advance!
The command should be
ffmpeg -loglevel info -r 4 -s 160x120 -f video4linux2 -i /dev/video0 http://localhost/webcam0.ffm
I think the address got dropped to the second line in the post.
Hello Sir thank you so much for this tutorial
But I am facing some problem in Streaming 2 webcams at a same time
My raspberry not Streaming both webcams at same time please help me
my ffserver.conf fille is like
Port 8090
# bind to all IPs aliased or not
BindAddress 0.0.0.0
# max number of simultaneous clients
MaxClients 10
# max bandwidth per-client (kb/s)
MaxBandwidth 1000
# Suppress that if you want to launch ffserver as a daemon.
NoDaemon
File /tmp/feed1.ffm
FileMaxSize 10M
File /tmp/feed2.ffm
FileMaxSize 10M
Feed feed1.ffm
Format mpjpeg
VideoFrameRate 4
VideoSize 600×480
VideoBitRate 80
# VideoQMin 1
# VideoQMax 100
VideoIntraOnly
NoAudio
Strict -1
Feed feed2.ffm
Format mpjpeg
VideoFrameRate 4
VideoSize 600×480
VideoBitRate 80
# VideoQMin 1
# VideoQMax 100
VideoIntraOnly
NoAudio
Strict -1
and my webcam.sh file is
ffserver -f /etc/ffserver.conf & ffmpeg -v verbose -r 5 -s 600×480 -f video4linux2 -i /dev/video0 http://localhost:8090/feed1.ffm
ffserver -f /etc/ffserver.conf & ffmpeg -v verbose -r 5 -s 600×480 -f video4linux2 -i /dev/video1 http://localhost:8090/feed2.ffm