I had some operas lying around amongst others Wagner's "Ring Des Nibelungen", Puccini's "La Boheme" and Verdi's "La Traviata". Sadly, some of them were not stored as flac but as monkey's audio (extension .ape) which is a non-free lossless codec but fortunately ffmpeg has a GPL'd decoder included. Additionally some CD's were stored as a single file with a cue sheet next to them.
So my task was: convert ape to flac, split audio by information from cue files and tag everything correctly.
These were the lines I used to split the audio:
ffmpeg -i CD1.ape CD1.wav shnsplit -o flac -f CD1.cue -t "%a %n %t" CD1.wav rm *pregap.flac CD1.wav CD1.ape cuetag CD1.cue *.flac
First ape is converted to wav so that shnsplit can read it. Shnsplit will then take the timing information from the cue sheet and split the wav into chunks which it conveniently also converts to flac on the fly. Sadly it doesnt do tagging of those files so this is done by cuetag afterward with information from the cue sheet. You need the shntool and cuetools packages.
Other data was already existing as separate tracks and only had to be converted from ape to flac. Sadly flac offers no means for batch conversion but using a for loop and basename the same effect is created. Conveniently ffmpeg will copy the tags from the ape files to the new flac files as well.
for f in *.ape; do b=`basename $f .ape`; ffmpeg -i "$b".ape "$b".flac; done
The resulting flac files were about 3-5% larger than the ape files which is a totally acceptable tradeoff for being able to ditch an unfree format.
thomasg pointed out to me, that using the zsh there is an even neater way to do this loop without basename(1) and without some shell-loop keywords:
for f in *.ape; ffmpeg -i $f $f:r.flac