I have a rtsp video-source stream1 and an audio source I currently merge and send to a rtmp-server using:
stream1="rtsp://streamurl1"
/usr/bin/ffmpeg \
[...]
-i "$stream1" \
[...]
-itsoffset $AUDIOVIDEOOFFSET \
-f pulse \
-i default \
[...]
-vcodec copy \
-map 0:v -map 1:a \
[...]
-f flv "rtmp://streamingserver"
I would now like to add a second video source
stream2and switch betweenstream1andstream2back and forth without interrupting the audio. Both streams are identical / come from identical cameras.
Is there any sane way to do this with ffmpeg? Or how would you recommend doing it?
Just stopping the process and restarting it using stream2 instead of stream1 works but results in several seconds outage on the stream and is the current worst case scenario I would like to improve.
I couldn't get it to work with pure
ffmpegin a reasonable amount of time but the nginx-rtmp module worked out of the box.It's basically
apt install libnginx-mod-rtmp nginx, add .... to nginx.conf,
systemctl restart nginxandnginxacts as a local loop-back device onrtmp://localhost/live.If you now have n streams to multiplex, you can create n systemd services
camera_i.serviceand switch to stream i by starting
camera_i.service:All other services listed on the
Conflicts=option are automatically being terminated by systemd, effectively multiplexing the camera streams.The resulting stream can then be recorder used using something like the following:
The result is a rather smooth flip with continuous audio.
-use_wallclock_as_timestamps 1 -fflags +genptsmight be unnecessary if you don't use-vsync 0. But I haven't tested that yet.Appendix
As has been proposed on the ffmpeg mailing-list, there is the
zmqfilter that supposedly can change filters settings on-the-fly. The idea is to overlay two streams and toggle the opacity of the top stream, effectively switching stream.I couldn't get it to work but for anyone to try:
where
zmqsendresults from: