Last active
December 8, 2024 03:53
-
-
Save mikaelz/12b394334e3226d67a37399d40751d8f to your computer and use it in GitHub Desktop.
Grid/mosaic view RTSP streams with ffmpeg based on https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ffmpeg -rtsp_transport tcp \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/102 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/202 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/302 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/402 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/502 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/602 \ | |
-filter_complex " | |
nullsrc=size=1920x1080 [base]; | |
[0:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [upperleft]; | |
[1:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [upperright]; | |
[2:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [middleleft]; | |
[3:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [middleright]; | |
[4:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [lowerleft]; | |
[5:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [lowerright]; | |
[base][upperleft] overlay=x=0:y=0 [tmp1]; | |
[tmp1][upperright] overlay=x=960:y=0 [tmp2]; | |
[tmp2][middleleft] overlay=x=0:y=360 [tmp3]; | |
[tmp3][middleright] overlay=x=960:y=360 [tmp4]; | |
[tmp4][lowerleft] overlay=x=0:y=720 [tmp5]; | |
[tmp5][lowerright] overlay=x=960:y=720 | |
" \ | |
-c:v rawvideo -f nut - | mpv - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 8 channel input, 4 rows and 2 columns layout | |
ffmpeg -rtsp_transport tcp \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/102 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/202 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/302 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/402 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/502 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/602 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/702 \ | |
-i rtsp://smartiptv:[email protected]/Streaming/Channels/802 \ | |
-filter_complex " | |
nullsrc=size=1920x1080 [base]; | |
[0:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [upperleft]; | |
[1:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [upperright]; | |
[2:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [middleleft]; | |
[3:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [middleright]; | |
[4:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [lowerleft]; | |
[5:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [lowerright]; | |
[6:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [centerleft]; | |
[7:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [centerright]; | |
[base][upperleft] overlay=x=0:y=0 [tmp1]; | |
[tmp1][upperright] overlay=x=960:y=0 [tmp2]; | |
[tmp2][middleleft] overlay=x=0:y=270 [tmp3]; | |
[tmp3][middleright] overlay=x=960:y=270 [tmp4]; | |
[tmp4][lowerleft] overlay=x=0:y=540 [tmp5]; | |
[tmp5][lowerright] overlay=x=960:y=540 [tmp6]; | |
[tmp6][centerleft] overlay=x=0:y=810 [tmp7]; | |
[tmp7][centerright] overlay=x=960:y=810 | |
" \ | |
-c:v rawvideo -f nut - | mpv - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -rtsp_transport tcp \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/101 \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/201 \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/301 \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/401 \ | |
-filter_complex " | |
nullsrc=size=1920x1080 [base]; | |
[0:v] setpts=PTS-STARTPTS, scale=960x540 [upperleft]; | |
[1:v] setpts=PTS-STARTPTS, scale=960x540 [upperright]; | |
[2:v] setpts=PTS-STARTPTS, scale=960x540 [lowerleft]; | |
[3:v] setpts=PTS-STARTPTS, scale=960x540 [lowerright]; | |
[base][upperleft] overlay=shortest=1 [tmp1]; | |
[tmp1][upperright] overlay=shortest=1:x=960 [tmp2]; | |
[tmp2][lowerleft] overlay=shortest=1:y=540 [tmp3]; | |
[tmp3][lowerright] overlay=shortest=1:x=960:y=540 | |
" \ | |
-c:v libx264 -preset superfast -crf 18 -f matroska - | ffplay - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -rtsp_transport tcp \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/102 \ # use substream with lower resolution | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/202 \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/302 \ | |
-i rtsp://smartiptv:[email protected]:6911/Streaming/Channels/402 \ | |
-filter_complex " | |
nullsrc=size=1920x1080 [base]; | |
[0:v] setpts=PTS-STARTPTS, scale=960x540 [upperleft]; | |
[1:v] setpts=PTS-STARTPTS, scale=960x540 [upperright]; | |
[2:v] setpts=PTS-STARTPTS, scale=960x540 [lowerleft]; | |
[3:v] setpts=PTS-STARTPTS, scale=960x540 [lowerright]; | |
[base][upperleft] overlay=shortest=1 [tmp1]; | |
[tmp1][upperright] overlay=shortest=1:x=960 [tmp2]; | |
[tmp2][lowerleft] overlay=shortest=1:y=540 [tmp3]; | |
[tmp3][lowerright] overlay=shortest=1:x=960:y=540 | |
" \ | |
-c:v libx265 \ # check output and see what format the camera use, see `ffmpeg -encoders | grep V` | |
-preset superfast -crf 18 -f matroska - | ffplay - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, but why don't use FFPLAY directly in place of piped FFMPEG instead ?
Check here: https://stackoverflow.com/questions/68824225/bad-ffmpeg-performace-compared-to-ffplay-and-vlc
About HW accelleration, check out these interesting posts:
...@cpcloud's ffgrid.sh may inspire too.
Another cool approach is cinegrid by @s7sost.
Someone suggests to use xstack filter for better performances:
Last but not least, it would be great to let FFMPEG get the screen resolution and adapt the mosaic (and source videos) to it:
https://superuser.com/questions/841235/how-do-i-use-ffmpeg-to-get-the-video-resolution
EDIT:
Just played a bit with ffplay and this seems to work flawlessly with local files...
@ffplay -autoexit -f lavfi "movie=<filename1>:seek_point=0.0, drawtext=verdana.ttf:text='TEST':fontcolor=white:fontsize=24:box=1:[email protected]:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)-5, scale=960:-1, setpts=PTS-STARTPTS[v0];movie=<filename2>:seek_point=0.0, scale=960:-1, setpts=PTS-STARTPTS[v1];[v0][v1]hstack"
Hope that inspires !