Multiple Video Streams in one Feed ffmpeg

trueblue picture trueblue · Oct 29, 2013 · Viewed 7.2k times · Source

We are trying to send live stream from two webcams as below :

ffmpeg -f video4linux2 -i /dev/video0 -f video4linux2 -i /dev/video1 http://127.0.0.1:8090/feed1.ffm

We want to play both the streams using any players available. When we use VLC, to open the stream, we get only one stream( from /dev/video0). The command is as below:

vlc http://127.0.0.1:8090/test.mpg

Here I am running ffserver in my machine and trying to access as localhost. My ffserver config is as below :

Port 8090
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
NoDaemon

<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 1G
ACL allow 127.0.0.1
</Feed>

<Stream test.mpg>

# coming from live feed 'feed1'
Feed feed1.ffm
Format mpeg
VideoBufferSize 40000
VideoSize 1280x720
VideoCodec mpeg1video
NoAudio
ACL ALLOW 127.0.0.1
</Stream>

<Stream stat.html>
Format status

# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255

#FaviconURL http://pond1.gladstonefamily.net:8080/favicon.ico
</Stream>


# Redirect index.html to the appropriate site

<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>

If we try the below command to save two streams onto the file, we are getting two instances of VLC player and both Streams can be seen :

ffmpeg -f video4linux2 -i /dev/video0 -f video4linux2 -i /dev/video1 /home/2Streams.mpg

Its a strange behavior I am able to save two Video Streams as a file but I am unable to send Two Video Streams in one Single feed. Kindly help me out in achieving the same.

Regards

Answer

Simon picture Simon · Feb 1, 2014

One may consider using overlay filter of ffmpeg to display both videostreams side by side or picture-in-picture (assuming both video sources have resolution 320x240), like so:

ffmpeg -i... -i... -filter_complex "nullsrc=size=640x240 [base]; [base][0:v] overlay [tmp]; [tmp][1:v] overlay=x=320" output.mpg

However, the documentation states that in the presence of 2 or more input streams of the same type, ffmpeg chooses "the better" one and uses it to encode the output. That's why VLC shows a single stream.

I'm a bit confused on how did you manage to save both streams into a single file (your last code snippet). When I need to do something like this I use -map option, e.g.:

ffmpeg -i... -i... -map 0:0 -map 1:0 output.mkv

Hope this helps.