Skip to content

Instantly share code, notes, and snippets.

@pabsan-0
Created August 9, 2022 12:59
Show Gist options
  • Save pabsan-0/61dbb0c3ceb80e501c02ecf404912e6f to your computer and use it in GitHub Desktop.
Save pabsan-0/61dbb0c3ceb80e501c02ecf404912e6f to your computer and use it in GitHub Desktop.
Display of 4 cameras with gstreamer
#! /usr/bin/bash
# This script to plot an array of 4 cameras with gstreamer
#
# To have them in sequence, define d0-d3 in increasing order, then circle your
# hand through all cameras. Change d0-d3 to the order your hand appears in.
# Then, you'll get a spatially coherent display of cameras next to each other.
# Ids from /dev/videoXX, get with `$ gst-device-monitor-1.0 | grep v4l2src`
d0=7
d1=11
d2=9
d3=3
# Image width/height. The pipeline will rotate the cameras so they're swapped
IM_W=240
IM_H=320
# The pipeline itself
gst-launch-1.0 \
videomixer name=mix \
sink_0::xpos=0 sink_0::ypos=0 \
sink_1::xpos=240 sink_1::ypos=0 \
sink_2::xpos=480 sink_2::ypos=0 \
sink_3::xpos=720 sink_3::ypos=0 \
! videoscale \
! "video/x-raw,width=$(("$IM_W" * 4 * 5/3))" \
! ximagesink sync=0 \
v4l2src device="/dev/video$d0" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d0" font-desc="Sans, 72" ! queue ! mix. \
v4l2src device="/dev/video$d1" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d1" font-desc="Sans, 72" ! queue ! mix. \
v4l2src device="/dev/video$d2" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d2" font-desc="Sans, 72" ! queue ! mix. \
v4l2src device="/dev/video$d3" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d3" font-desc="Sans, 72" ! queue ! mix. ;
## This other pipeline using compositor rather than videomixer
## Cant be resized easily after stream
# gst-launch-1.0 \
# v4l2src device="/dev/video$d1" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d1" font-desc="Sans, 72" ! queue ! comp. \
# v4l2src device="/dev/video$d0" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d0" font-desc="Sans, 72" ! queue ! comp. \
# v4l2src device="/dev/video$d2" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d2" font-desc="Sans, 72" ! queue ! comp. \
# v4l2src device="/dev/video$d3" ! "video/x-raw,width=$IM_H,height=$IM_W" ! videoflip method=clockwise ! textoverlay text="$d3" font-desc="Sans, 72" ! queue ! comp. \
# compositor name=comp \
# sink_0::xpos=0 \
# sink_1::xpos=$(("$IM_W")) \
# sink_2::xpos=$(("$IM_W"*2)) \
# sink_3::xpos=$(("$IM_W"*3)) \
# ! videoscale \
# ! "video/x-raw,width=800,height=600" \
# ! ximagesink ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment