Category Archives: Audio/Video

Conquer Giant FLAC

I have already written posts on splitting and converting from either album-length APE files or album-length FLAC files into track-length FLAC files.

(My post on converting APE files; my post on splitting APE files; my post on splitting FLAC files. You will want to go over these other articles if you have not done any of this before as there are some dependencies which you will not likely have installed.)

That was rather satisfying, but I then found that I would locate entire discographies where every album was a single APE or FLAC.  I did not enjoy the prospect of running each command on each pair of files.

That’s why scripting languages exist.  It’s a good thing I bought that BASH book.

Anyway, this script is designed to recursively locate APE, FLAC, and CUE files under a user-supplied root directory; then it runs shntool and cuetag on each APE/FLAC and CUE pair.  (You can read my previous posts linked above for more details about how these two commands work.)

It even cleans up after itself.  Since it deletes not only the temporary files it creates but also all the APE, FLAC, and CUE files it uses, you will want to pay close attention when the script tells you it is about to clean up all those files.  If you tell it to proceed (by hitting ENTER) without checking its work all those files will be deleted.  As such you should work from copies and you should check that it did what you wanted it to do before hitting ENTER when it asks about cleaning up all files.

Feel free to suggest any improvements.  I hope you find that it works well and improves your lives.

One important thing to note is that it is not an intelligent script.  It cannot determine for you whether a given APE or FLAC file is actually album length.  It assumes that you are offering it a folder (with or without sub-folders) which contains only album-length APE or album-length FLAC files with an accompanying CUE file (one matching pair per containing folder).

Sometimes a cue file will be formatted incorrectly or have some other issue.  Sometimes they can be fixed by opening them in a text editor.  Probably they can always be fixed in a text editor, but it might be difficult to determine what’s wrong with the CUE file.  If a CUE files has issues you will see errors on the command line (if you are staring at your monitor) and the album-length file will not be split/tagged.  You’ll have to work on that pair separately, but since you are working from copies it won’t matter if they get deleted.

If you throw something unusual at it, it’s hard to imagine how it might behave.  It’s likely not dangerous but you should always work from copies and preserve the originals until you are satisfied.

A couple of things have changed since I first wrote this script and article.  First, the script no longer accepts ape files as input.  You will want to convert them directly into flac files before splitting.  This is very easy and at some point I’ll add notes on how to do that.  Second, the script no longer lives here because it’s easier for me to maintain and share them over at GitHub.

splitFLAC.sh at GitHub

Have a great time!


Share

Little Apes to FLAC Files

The below article remains for archive purposes.  You can now easily convert APE directly to FLAC with ffmpeg.

##

# One command per ape... 

ffmpeg -i inputname.ape outputname.flac 

# ... in a loop cd into containing folder and... 

for apeFile in *.ape ; do 
    ffmpeg -i "${apeFile}" "${apeFile%\.ape}.flac" 
done 

##

You may come across individual APE files which you would like to convert to FLAC files.  This can be especially useful if you have an album FLAC and an accompanying CUE file and you are having trouble getting the APE to burn correctly.

There is a fairly simple tool for dealing with this conversion.  As fortune would have it this tool will also manage conversions to and from ALAC, SHN, TTN, and WAVE files.  How can they pack so much fun into such a small package?  Now it’ll be that much easier to clean your collection up and keep everything tidy: flacflacflac.

Ok, so you’ll need—and if you’ve been following along here you already have—the MAC (Monkey Audio Codec).

Next you’ll need to get something called apeinfo.   There exist both 32 and 64 bit versions so be sure you get the proper version for whichever Ubuntu you are running.  You will find them here.  You will want to change the name of the file you download to merely apeinfo (so remove the _32 or _64) or it won’t work when called up by the next tool.

The next tool being known as convtoflac.  You may find that here.

Download both of your files and they all gets stuck into /usr/local/bin.

I downloaded each of these to my desktop and then used sudo to copy them into /usr/local/bin.  Make certain you have given them execute permissions (set the execute bit).  By storing them in /usr/local/bin I am sure they are in my command path (basically those places your system looks when you type a command) and they are ready to use.  Here is the command you need to move the apeinfo file from the Desktop to /usr/local/bin:

sudo mv /home/[usename]/Desktop/apeinfo /usr/local/bin/apeinfo

You can copy and paste that line and make the necessary substitutions for your system, download location, and specific file.

Once you have these installed correctly you are ready to use the tools to make conversions.  I have written a small simple script for making all of this work together.  If you make my script executable and place it  in your /usr/local/bin you can merely call the whole thing up by typing the name of the command (whatever you decide to name your version of my script) in your terminal.  I named my script Ape2Flac.sh.

##
#!/bin/bash
# by JamesIsIn from JamesIsIn.com
# Do something nice today.

#  Ape2Flac.sh

#  also requires apeinfo and convtoflac
#  http://jamesisin.com/a_high-tech_blech/?p=1335

for i in *.ape
do convtoflac.sh "$i"
done

##

This method will preserve any existing tags.

To fire it up, navigate into the folder in which you have the APE files and run my script (by typing its name into the command line).  It’s that easy.

See, nothing to fear from the command line.

Happy hunting.

Share

Make a Big APE into Several Small, Tagged FLAC Files

The below article remains for archive purposes.  You can now easily convert APE directly to FLAC with ffmpeg.

##

# One command per ape... 

ffmpeg -i inputname.ape outputname.flac 

##

You may recall with great excitement my post on splitting and tagging album length FLAC files into track length FLAC files.  It may come to pass that you find yourself staring at an album length APE file.

What?  What the hell is an APE file?

In short, some folks decided “hey, what the world needs is another media player and it’s very own lossless codec”.  In their defense, MediaMonkey looks like a pretty cool application (say “iTunes killer”), and it does support FLAC and OGG so I don’t dispise it.  Nonetheless, it is my advice to avoid specialized and proprietary codices wherever possible.  Unfortunately Monkeys, this means no APE files.

As fate would have it, if you are already set up to split and tag an album FLAC, you are nearly ready to do the same for an album APE.  You just need the MAC (monkey audio codec).

You have two choices.  This codec isn’t part of what Canonical normally provides, so you can either add a repository which includes it or you can download the codec directly.  I tend to prefer adding a repository, but the codec can be downloaded in this package.

http://members.iinet.net.au/~aidanjm/mac-3.99-u4_b3-1_i386.deb

(If you choose to download the .deb package, double-clicking on it once you have downloaded it and your system will run the installation.)

For those of you, like me, who prefer to add a repository, the Eudoxos repositories include MAC, so we can add this one.

http://ppa.launchpad.net/eudoxos/ubuntu yourubuntuversion main

Once you have added that repository Monkey Audio will appear in Synaptic.  To install the Monkey Shite open Synaptic and look for Monkey Audio. (Please note that newer editions of this repository no longer carry the MAC, yet I am using the repo for 8.10 in my 10.04 machine successfully.)

Now let’s get to the meat of it.  I have grown lazy and tend to rename my FLAC, APE, and cue files to the letter a, so my commands look like this:

##

# Here are the two commands you will need

shnsplit -o flac -f a.cue -t "%n – %t" a.ape

# Note: you may substitute "%n - %a - %t" if you want artist names in your file names

# now you may move or remove the album APE]

cuetag a.cue *.flac

##

Unlike splitting a FLAC file into smaller flac files, you don’t necessarily have to send the album length APE to the trash (or remove it’s file extension) between performing these two commands.  But you can.

If this isn’t strait forward, you may want to read through my previous post to sort out the details of the conversion process and then come to this post for the APE specific information.

Thanks to this post for some information.

Share

Split a FLAC and Tag the Children using Cue Information

(Though this article will still be useful to some, most users will prefer my updated article here.)

It may come to pass that you download a concert or album only to discover that the encoder has helped you out by encoding the entire thing as a single FLAC file accompanied by a .cue file for determining the track changes.  Rhythmbox, for instance, will play these large FLAC’s just fine and it will even display the correct track information as you progress through the file.  However, I find it much more palatable to have single tracks be single files.

It’s actually pretty easy to break that large FLAC file into its component tracks and to add the appropriate tag information into those individual FLAC files.  It only requires a couple of lines of code, in fact.  The code may look complicated, but once you understand how to parse the different pieces you should have no difficulty in manipulating the code to process your files.

Before you begin with that you will want to add two utility packages which contain the tools you will need to make these splits and do the tagging of the individual files.  Open a terminal (Applications —> Accessories —> Terminal) and run these two commands:


sudo apt-get install shntool
sudo apt-get install cuetools

It doesn’t matter in which order you run them but you will need both packages.

First I offer a couple of examples of how the code might look.  Suppose you have a folder which contains a Van Morrison album as a single flac (and the cue file is in there as well).  In your terminal (Applications —> Accessories —> Terminal) navigate into that folder (using the cd command).  Your commands might look like such:

## Two commands as an example
#

shnsplit -o flac -f "Van Morrison - Astral Weeks.cue" -t "%n – %t" "Van Morrison - Astral Weeks.flac"

cuetag "Van Morrison - Astral Weeks.cue" 0*.flac

#

As I said, the code looks a little complex but let’s look at another example.  Suppose you have volume one from the Hôtel Costes series by Stéphane Pompougnac.  Your code might look like this:

## Two commands in a different example
#

shnsplit -o flac -f VA-Hotel_Costes_1.cue -t "%n – %t" VA-Hotel_Costes_1.flac

cuetag VA-Hotel_Costes_1.cue *.flac

#

As you can see, certain elements do not change.  What changes is your particular file names.  In the Van Morrison example the files contain spaces and said spaces must be preceded by a slash in order to be taken as a space within the file name (or you must quote the entire file name).  In the end what you are really seeing is this (the square brackets are only there to remind you what needs replacing):

## More examples for better understanding
#

shnsplit -o flac -f [cuefile].cue -t "%n – %t" [albumflac].flac
# OR
shnsplit -o flac -f "cue file.cue" -t "%n – %t" "album flac.flac"
# OR
shnsplit -o flac -f cue\ file.cue -t "%n – %t" album\ flac.flac

cuetag [cuefile].cue *.flac

# &c

#

I like to change both my FLAC  and cue files to the name a.  Also, you may or may not want to add the name of the performer in your file names. (I only include the performer names on various artist albums. So you know, %a is for Album and %p is for performer.) Then I can simply run (no slashes; no quotes around the file names):

## Choose one of these first two
## Then run the last

shnsplit -o flac -f a.cue -t "%n – %t" a.flac
# OR
shnsplit -o flac -f a.cue -t "%n – %p – %t" a.flac

cuetag a.cue *.flac

#

(Be sure to either send the album FLAC to the trash or change its file extension after running the first command but before running the second, or you will get an error about having the wrong number of FLAC files.)

Let me explain that zero (0) in the Van Morrison example.  That album happens to have fewer than 10 tracks.  So all of the tracks begin with a zero (01, 02, &c).  That is not the case on the Hôtel Costes album; it has tracks 11, 12, 13, &c.  You must add something like .remove to the album FLAC (so VA-Hotel_Costes_1.flac.remove) or move to different location (like the trash) after you have run the first command and before you run the second command (since the album FLAC file also ends in .flac and would be within the scope of *.flac).  If you leave the original FLAC within range, cuetag will inform you that the number of tracks does not match the number of cue breaks and it will not tag the files.  Not a big deal, but it could be a point of confusion if you were not prepared properly for it.

There are other arguments besides those which I used in my commands above.  You can read quite a lot about similar methods here.

Happy hunting, music lovers.

Share