Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2013 22:43
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 anonymous/4464109 to your computer and use it in GitHub Desktop.
Save anonymous/4464109 to your computer and use it in GitHub Desktop.
Small bash script to extract audio from video files.
#!/bin/bash
# Some consts
OUT_CODEC="libvorbis"
OUT_EXTENSION=".ogg"
pids=""
# Kick off the conversions
for file in *
do
mime_type=$(file --brief --mime-type ${file})
# Discard the subtype:
mime_type=${mime_type%/*}
if [ "${mime_type}" = "video" ]
then
# Build the outfile
outfile="${file%.*}${OUT_EXTENSION}"
# Consider existence to mean that it's been done before
if [ -e "${outfile}" ]
then
echo "Skipping ${file} (destination exists)..."
continue
fi
# Announce it:
echo -n "${file} TO ${outfile}..."
# Do the conversion
avconv -i "${file}" -vn -acodec ${OUT_CODEC} ${outfile} &> /dev/null &
pid=$!
echo "${pid}"
pids="$pids $pid"
fi
done
failed=""
# Waiting...
for pid in ${pids}
do
echo "${pid} is pending..."
wait ${pid} || failed="${failed} ${pid}"
done
if [ -z "${FAIL}" ]
then
echo "Done."
else
echo "Process(es) failed (${FAIL}), check state manually."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment