Skip to content

Instantly share code, notes, and snippets.

@shantur
Created September 2, 2016 09:19
Show Gist options
  • Save shantur/1eab3b8e8b427392c3dc35e491647a29 to your computer and use it in GitHub Desktop.
Save shantur/1eab3b8e8b427392c3dc35e491647a29 to your computer and use it in GitHub Desktop.
Converts all mp4 files in a folder tree to another folder tree
#!/bin/bash
# loop & print a folder recusively,
recurse() {
echo $1 $2 $3
for i in "$1"/*;do
if [ -d "$i" ];then
outputdir=`echo $i | sed "s/$2/$3/g"`
echo "outputdir: $outputdir"
mkdir -p "$outputdir"
recurse "$i" "$2" "$3"
elif [ -f "$i" ]; then
outputfile=`echo $i | sed "s/$2/$3/g"`
outputfile=`echo $outputfile | sed "s/mp4/mp3/g"`
convert "$i" "$outputfile"
fi
done
}
convert() {
input=$1
output=$2
ffmpeg -i "$input" -vn -ab 256 "$output"
}
echo "convert from path: $1 to $2"
mkdir -p "$2"
recurse "$1" "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment