This is just a short bash script to process a directory hierarchy of MP4 video files, copying just the audio out to a similar directory structure, creating the directories as well. Something to save the battery life of my iPhone, when I'd rather just listen to stuff that doesn't need watching as well.
The script is usefully fast as no transcoding takes place, the output file format is whatever was in the MP4 container - I'm just assuming aac/.m4a here as that was what was originally in my source files.
#!/bin/bash
#
# This script searches $vDir for mp4 files placing
# processed copies in a similar directory structure under $mDir.
vDir=/home/adrian/Videos/Music
mDir=/home/adrian/Music/Artists
find $vDir -type f -name *.mp4 |
while read -r src ; do
dst=$(echo $src | sed 's/.mp4$/.m4a/' | sed "s=$vDir=$mDir=" )
# has audio been previously extracted?
if [ ! -e "$dst" ]; then
dstDir=$(dirname "$dst")
# does dest directory not exist?
if [ ! -d "$dstDir" ]; then
echo "*** creating $dstDir"
mkdir -p "$dstDir"
fi
echo "*** extracting audio from $src"
ffmpeg -nostdin -i "$src" -c:a copy -vn -sn "$dst"
fi
done
echo "Finished."
Note the '-nostdin' switch to avoid ffmpeg sucking up the piped output of 'find' as interactive input! Had a nice tail chase fixing that!
No comments :
Post a Comment