Skip to content

Instantly share code, notes, and snippets.

@sehrgut
Last active December 17, 2015 17:19
Show Gist options
  • Save sehrgut/5644682 to your computer and use it in GitHub Desktop.
Save sehrgut/5644682 to your computer and use it in GitHub Desktop.
squint - a bash script for cygwin to rip audio tracks from YouTube video files wihtout transcoding
#!/usr/bin/bash
# Licensed under any of GPLv2, MIT, and BSD 2-clause licenses
FFDIR=`cygpath -u $USERPROFILE`"/bin/ffmpeg/bin"
infile=`cygpath -w "$1"`
outfile=`cygpath -w "${1%.*}"`
echo $1
FFPROBE="$FFDIR/ffprobe.exe"
FFMPEG="$FFDIR/ffmpeg.exe"
codec=`"$FFPROBE" -loglevel quiet -show_streams -select_streams a -i "$infile" | \
sed -En 's/codec_name=(.*)/\1/p'`
printf "Found codec '%s'\n" "$codec" >&2
case "$codec" in
'aac')
opts='-acodec copy'
ext='m4a'
;;
'mp3')
opts='-acodec copy'
ext='mp3'
;;
*)
opts='-acodec mp3 -qscale 0'
ext='mp3'
esac
if [[ -n $2 ]]; then
outopts="-ss $2"
fi
printf "Using ffmpeg options '%s'\n" "$opts" >&2
printf "Saving '%s.%s'\n" "$outfile" "$ext" >&2
"$FFMPEG" -i "$infile" $opts -vn -loglevel error $outopts "${outfile}.${ext}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment