Skip to content

Instantly share code, notes, and snippets.

@s-zeid
Last active August 29, 2015 14:07
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 s-zeid/4277d59403c12ed33b3f to your computer and use it in GitHub Desktop.
Save s-zeid/4277d59403c12ed33b3f to your computer and use it in GitHub Desktop.
Play deinterlaced video with sound from a video capture card with minimal lag, on GNU/Linux, saveable as raw video and audio in a Matroska container.
#!/bin/sh
# Copyright (c) 2014 Scott Zeid.
# Released under the X11 License <https://tldrlegal.com/license/x11-license>.
cap() {
local video=$1
local audio=$2
ffmpeg \
-f v4l2 -i "$video" \
-f alsa -i "$audio" \
-vcodec rawvideo -acodec copy \
-vf kerndeint \
-f matroska -
}
save() {
local out=$1
[ x"$out" != x"" ] && tee "$out" || cat
}
play() {
local title=$1
ffplay -window_title "$title" -
}
capplay() {
if [ x"$1" = x"" ] || [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then
echo "Usage: $0 <video-file> hw:<card>,<device> [title] [-o|--output output-file.mkv]"
([ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]) && return 0 || return 2
return 0
fi
local video=$1; shift
local audio=$1; shift
if [ x"$1" != x"-o" ] && [ x"$1" != x"--output" ]; then
local title=$1; shift
else
local title=
fi
if [ x"$1" = x"-o" ] || [ x"$1" = x"--output" ]; then
shift
local out=$1; shift
else
local out=
fi
cap "$video" "$audio" | save "$out" | play "$title"
}
main() { capplay "$@"; }
main "$@"
#!/bin/sh
# Copyright (c) 2014 Scott Zeid.
# Released under the X11 License <https://tldrlegal.com/license/x11-license>.
first() { printf '%s' "$1"; }
TITLE="OTG102"
VIDEO=`first /dev/v4l/by-id/usb-Geniatech_Inc._Video_Capture_20090456-video-index*`
AUDIO=hw:`( pacmd list-sources; echo index: ) | awk 'BEGIN { want = 0; card = "" } /alsa.card / { card = $0 } /alsa.long_card_name.* cx231xx/ { want = 1 } /index:/ { if (want == 1) { print card; exit } }' | sed -e 's/[^"]*"\([^"]*\)".*/\1/g' -e 's/:/./g'`,0
main() {
if [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then
echo "Usage: $0 [title] [-o|--output output-file.mkv]"
return 0
fi
if [ x"$1" != x"-o" ] && [ x"$1" != x"--output" ]; then
local title=$1; shift
else
local title=
fi
title=${title:-$TITLE}
if [ x"$1" = x"-o" ] || [ x"$1" = x"--output" ]; then
shift
local out=$1; shift
else
local out=
fi
if [ x"$out" = x"" ]; then
capplay "$VIDEO" "$AUDIO" "$title"
else
capplay "$VIDEO" "$AUDIO" "$title" -o "$out"
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment