Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script gstreamer to grab from Terratec Grabby
#!/bin/bash
## Grab video from a cheap Terratec Grabby using gstreamer.
## Trivial script, but call it MIT licensed if you care.
## Harri Haataja, 2015-12-04
## From output of pactl list short sources
## Grabby doesn't activate properly until capture starts.
## TI box doesn't have preamp gain.
## Builtin is noisy (with gain).
#AUDIO_DEVICE="alsa_input.usb-TerraTec_Electronic_GmbH_TerraTec_Grabby-01.analog-stereo"
AUDIO_DEVICE="alsa_input.pci-0000_00_1b.0.analog-stereo"
#AUDIO_DEVICE="alsa_input.usb-BurrBrown_from_Texas_Instruments_USB_AUDIO_CODEC-00.analog-stereo"
## Could do some udev trickery for this.
VIDEO_DEVICE="/dev/video0"
## Rest of the chain
## Interlacing artifacts are pretty bad, but deinterlacing makes jerky movement. Is there a fix?
AUDIO_CAPABILITIES="audio/x-raw, channels=2"
VIDEO_CAPABILITIES="video/x-raw, width=720, height=576"
## Default or argument as outfile
OUTFILE="test.mp4"
if [ "$1" != "" ]; then
OUTFILE="$1"
fi
echo "capturing to ${OUTFILE}"
## Could abstract these as well, but it's easy to edit
## Some material has been quant 22 to 26
## Adjust for file size and material
## Key-int-max dropped for a more seekable and cuttable file
## My computer can handle "slower" in realtime, so "slow" for margin.
## Eq cuts some hiss from the audio.
## Audio bitrate is probably overkill.
gst-launch-1.0 -e --gst-debug=3 \
v4l2src device=${VIDEO_DEVICE} do-timestamp=true \
! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
! ${VIDEO_CAPABILITIES} \
! x264enc pass=quant quantizer=22 speed-preset=slow key-int-max=25 \
! progressreport update-freq=1 \
! mux. \
pulsesrc device=${AUDIO_DEVICE} do-timestamp=true \
! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
! ${AUDIO_CAPABILITIES} \
! equalizer-3bands band2=-9 \
! avenc_ac3 bitrate=192000 \
! mux. \
mp4mux name=mux \
! filesink location=${OUTFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment