Created
January 5, 2013 22:43
-
-
Save anonymous/4464109 to your computer and use it in GitHub Desktop.
Small bash script to extract audio from video files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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