Skip to content

Instantly share code, notes, and snippets.

@tobert
Created March 8, 2014 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobert/9426323 to your computer and use it in GitHub Desktop.
Save tobert/9426323 to your computer and use it in GitHub Desktop.
four streams, one mpegts
#!/bin/bash
# pulsesrc ⇨ audioconvert ⇨ lamemp3enc
# ⇩
# queue
# ⇩
# queue ⇨ x264enc ⇨ queue ⇨ mpegtsmux ⇨ filesink
# ⇧
# ⇧ queue ⇦ jpegdec ⇦ jpegparse ⇦ v4l2src
# ⇧ ⇙
# videomixer ⇦ queue ⇦ jpegdec ⇦ jpegparse ⇦ v4l2src
# ⇖
# queue ⇦ videoconvert ⇦ Terminal
set -e
queue_bytes=$((2**24)) # 16mb queues between threads
timestamp=$(date -Im)
# write the final video to this file
outfile="$HOME/Video/gst-video0-${timestamp}.mpts"
# both cameras will capture in MJPG mode even though the C920 has support for H.264/1080p
# since it looks like either h264 is lagging or USB is. In any case running the same mode
# on both matches things up nicely
camera_resolution="width=1280, height=720"
camera0="/dev/video0" # Logitech C920
camera1="/dev/video1" # Microsoft Lifecam
# pactl list short
microphone="alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201202-00-Snowball.analog-stereo"
# use xwininfo to get the window ID and update this
# I manually size the terminal window to 2560x1440 before running this script.
term_xid=0x4e0001d
set -x
gst-launch-1.0 --eos-on-shutdown -vvv \
mpegtsmux name=mux ! \
filesink location=$outfile \
videomixer name=mix sink_1::xpos=1280 sink_2::ypos=720 ! \
video/x-raw, width=2560, height=1440 ! \
queue max-size-bytes=$queue_bytes ! \
x264enc ! \
queue max-size-bytes=$queue_bytes ! \
mux. \
v4l2src device=$camera0 do-timestamp=true ! \
image/jpeg, $camera_resolution ! \
jpegparse ! jpegdec ! \
queue max-size-bytes=$queue_bytes ! \
mix. \
v4l2src device=$camera1 do-timestamp=true ! \
image/jpeg, $camera_resolution ! \
jpegparse ! jpegdec ! \
queue max-size-bytes=$queue_bytes ! \
mix. \
ximagesrc xid=$term_xid ! \
timeoverlay ! \
videoconvert ! \
queue max-size-bytes=$queue_bytes ! \
mix. \
pulsesrc device=$microphone name=microphone ! \
audioconvert ! \
lamemp3enc target=bitrate bitrate=64 cbr=true ! \
queue max-size-bytes=$queue_bytes ! \
mux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment