Convert to FLAC

Last Modified: Mon, 03/05/2007 - 01:26

Introduction

FLAC is a free, open source lossless compression audio codec.  The Convert to FLAC script, converts audio files compressed with alternative lossless codecs (Monkey's Audio, Shorten, etc.) to the FLAC format.  FLAC is my preferred audio format for archiving music, so I wanted an easy way to convert other formats to FLAC.  In addition to simply transcoding the file to the FLAC format, Convert to FLAC also preserves any existing tags from the original file.

Convert to FLAC is a BASH shell script, and was originally written for use under Linux.  It should, however, run under any OS that supports BASH.

Convert to FLAC currently supports the following input formats:

Return to top

Download  Current Version: 1.1, Released: 02/18/2007

convtoflac.sh (5.9 KB) - The Convert to FLAC BASH shell script

ChangeLog - Convert to FLAC development details

Return to top

Installation

Installation of Convert to FLAC is simple:

  1. Download the BASH script
  2. Copy to a directory in your $PATH (eg, /usr/local/bin/)
  3. Ensure that the script has the execute bit set (eg, chmod a+x /usr/local/bin/convtoflac.sh)
  4. Verify that required binaries are available for the format you want to encode (see supported formats list above)

To complete installation, please open up convtoflac.sh in any text editor and verify that the programs defined in the "Setup environment" section are installed, and modify the path to each as appropriate.

Return to top

Usage

Execute convtoflac.sh -h to display the convtoflac help information.  This will describe the syntax for running the program and list all available options.

When run on a supported audio file, convtoflac.sh will automatically determine the input filetype and transcode it to a FLAC file

Tip:  Convert to FLAC can only operate on a single audio file at a time.  However, if you need to process multiple files at once (such as an entire album), so you can so with a little shell magic:
for i in *.ape; do convtoflac.sh "$i"; done

This example converts APE files, but the same can be done for any supported filetype by changing the extension in the above command.

Return to top

Technical Details

convtoflac begins execution by verifying that all arguments have been passed correctly.  It the determines the input filetype by checking the extension (case-insensitive match).  Using the file command to more accurately identify the input file is not possible because it does not recognize every supported filetype.  Support files are then verified based on the input file format; eg., if you are missing wvunpack but are trying to convert an APE file, then you will not get an error about wvunpack.

convtoflac transcodes the file by piping the decompression output directly to the flac command to make the process as quick as possible.  flac will apply maximum compression to the file, and the resulting output file will have the same name as the original file, but with the .flac extension.

If the input file format includes tags, convtoflac will then attempt to apply the tags to the new FLAC file.  It does this by first outputting the tags from the original file to a temp file, converting the tags to the VORBISCOMMENT format if necessary (the tag format used by FLAC), then applying them to the new file using metaflac.

Depending on which options were passed, convtoflac may either delete or prompt you to delete the input file at this point.  If you passed the -d option, it will attempt to verify that transcoding was successful before deleting the file.  If not, convtoflac simply exists with an error message.

Return to top