#!/bin/bash
#
# Extracts tracks from stems files and puts them in folders
# named after the stem filenames.
#
for stem in *.mp4
do
name=${stem%\.*}
echo $name
# Create a directory
rm -R ./"$name"
mkdir $name
# Album cover
coverFilename="$name"/"$name"_cover.jpg
echo " - Extracting album cover to $coverFilename"
ffmpeg -i "$stem" -an -vcodec copy "$coverFilename"
# Audio tracks
for trackNo in 1 2 3 4
do
trackFilename="$name"/"$name"_"$trackNo".m4a
echo " - Extracting audio track $trackNo to $trackFilename"
ffmpeg -i $stem -map 0:$trackNo -vn "$trackFilename"
done
done