FFmpeg stack two videos and merge audios




FFmpeg -i rtmp://192.168.137.1:1935/live/xyz -i rtmp://192.168.137.1:1935/live/abc -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -an -f flv rtmp://192.168.137.1:1935/live/qwe


The above command stacks video from two streams and merges audios into one.


I tried following commands before I came up with above. 


ffmpeg -i rtmp://192.168.137.1:1935/live/xyz -i rtmp://192.168.137.1:1935/live/abc -filter_complex "[0:a][1:a]amix[a]" -map 0:v -map "[a]" -c:v copy -f flv rtmp://192.168.137.1:1935/live/qwe


ffmpeg -i rtmp://192.168.137.1:1935/live/xyz -i rtmp://192.168.137.1:1935/live/abc -filter_complex "[0v][1v]xstack=inputs=2:layout=0_0|1920_0[stacked]" -map "[stacked]" -preset ultrafast -vcodec libx264 -tune zerolatency -an -f flv rtmp://192.168.137.1:1935/live/qwe


ffmpeg -i rtmp://192.168.137.1:1935/live/xyz -i rtmp://192.168.137.1:1935/live/abc -filter_complex "[0v][1v]xstack=inputs=2:layout=0_0|1920_0[stacked];[0:a][1:a]amix[a]" -map "[stacked]" -map 0:v -map "[a]" -preset ultrafast -vcodec libx264 -tune zerolatency -an -f flv rtmp://192.168.137.1:1935/live/qwe


How to test?


Use Node Media ServerNode Media Server to start a local server that takes in rtmp streams and publishes.

Create two rtmp streams using OBS StudioOBS Studio stream them to Node Media Server and use the rtmp streams url in the FFmpeg command above to create a third rtmp stream which you can use anywhere you want.



Next Post Previous Post
No Comment
Add Comment
comment url