Skip to content

Instantly share code, notes, and snippets.

@schlomo
Created April 20, 2020 17:31
Show Gist options
  • Save schlomo/a04785c351ac1dfafa6fb1993066c34e to your computer and use it in GitHub Desktop.
Save schlomo/a04785c351ac1dfafa6fb1993066c34e to your computer and use it in GitHub Desktop.
video grabber script for PAL VHS video
#!/bin/bash
#
# record from video grabber
VIDEO=${VIDEO:-/dev/video1}
AUDIO=${AUDIO:-hw:1}
AUDIO_RATE=48000
VIDEO_IN="-f video4linux2 -video_size 720x576 -thread_queue_size 1024 -framerate 25 -i $VIDEO -vsync 1"
AUDIO_IN="-f alsa -sample_rate $AUDIO_RATE -channels 2 -thread_queue_size 2048 -itsoffset 0.3 -i $AUDIO"
AUDIO_FILTER="-af aresample=async=1000"
VIDEO_FILTER="-vf format=yuv420p,setdar=4/3"
ACODEC_MP3="-acodec mp3 -ar $AUDIO_RATE -ac 2 -b:a 128k $AUDIO_FILTER"
ACODEC_AAC="-acodec aac -ar $AUDIO_RATE -ac 2 -b:a 128k $AUDIO_FILTER"
function myffmpeg {
/usr/bin/ffmpeg -hide_banner "$@"
}
function mpeg4 {
output="$1" ; shift
myffmpeg \
$VIDEO_IN \
$AUDIO_IN \
-vcodec mpeg4 -b:v 3000k -r 25 $VIDEO_FILTER \
$ACODEC_AAC \
-movflags faststart "$output".mp4 \
-pix_fmt yuv420p -f opengl live -f pulse $AUDIO_FILTER live "$@"
}
function dvd {
output="$1" ; shift
myffmpeg \
$VIDEO_IN \
$AUDIO_IN \
-target pal-dvd -b:v 8000 $VIDEO_FILTER $AUDIO_FILTER \
"$output".mpg \
-pix_fmt yuv420p -f opengl live -f pulse $AUDIO_FILTER live "$@"
}
function h264 {
output="$1" ; shift
myffmpeg \
$VIDEO_IN \
$AUDIO_IN \
-vcodec h264 -preset faster -profile:v high -level 4.2 -tune film -crf 18 $VIDEO_FILTER \
$ACODEC_AAC \
-movflags faststart "$output".mp4 \
-f opengl $VIDEO_FILTER live -f pulse $AUDIO_FILTER live "$@"
}
function h264_complex {
output="$1" ; shift
myffmpeg \
$VIDEO_IN \
$AUDIO_IN \
-filter_complex "format=yuv420p,setdar=4/3,split=[file][screen];aresample=async=1000,asplit=[afile][ascreen]" \
-map '[file]' -map '[afile]' \
-vcodec h264 -preset faster -profile:v high -level 4.2 -tune film -crf 18 \
-acodec aac -ar $AUDIO_RATE -ac 2 -b:a 128k \
-movflags faststart "$output".mp4 \
-map '[screen]' -an \
-f opengl live \
-map '[ascreen]' -vn \
-f pulse live "$@"
}
function dv {
output="$1" ; shift
myffmpeg \
$VIDEO_IN \
$AUDIO_IN \
-target pal-dv $VIDEO_FILTER $AUDIO_FILTER \
"$output".dv \
-pix_fmt yuv420p -f opengl live -f pulse $AUDIO_FILTER live "$@"
}
function watch {
ffmpeg $VIDEO_IN $AUDIO_IN -pix_fmt yuv420p $VIDEO_FILTER -f opengl live -f pulse $AUDIO_FILTER live "$@"
}
#mode="$1" ; shift
mode=h264_complex
$mode "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment