Converting FLAC to ALAC, preserving tags - in a script

6,849

Solution 1

The current ffmpeg (version 2.0.2 as I write this) supports both decoding and encoding for ALAC. And it copies global metadata from the first input file by default.

Invoking it like this:

ffmpeg -i track01.flac -c:a alac track01.m4a

produced an ALAC file with the metadata copied.

Solution 2

If source audio file has an embedded cover art, ffmpeg will convert that into a video, which is probably not what you want. Complete command is:

ffmpeg -i file.flac -vn -acodec alac file.m4a

And in batch mode:

ls *flac | while read f; do
    ffmpeg -i "$f" -acodec alac -vn "${f[@]/%flac/m4a}" < /dev/null;
done

The -vn switch will make ffmpeg ignore "video" parts of source file. Tags will be transferred to destination file, but I'd prefer to use Picard tagger to retag the new files using a robust artist/work/release database as MusicBrainz.

Here are more advanced techniques:

https://avi.alkalay.net/2016/09/multimedia-linux-cli.html

Share:
6,849

Related videos on Youtube

Eric Astor
Author by

Eric Astor

Updated on September 18, 2022

Comments

  • Eric Astor
    Eric Astor almost 2 years

    I'm currently building a script to maintain parallel music libraries, because I have devices that can't play FLAC, but prefer to store my music in that format. However, I'm having some trouble with the part that converts FLAC to ALAC. It currently just dispatches FFMPEG to do the job. However, FFMPEG (version 0.5.9) can't seem to preserve the tags! -map_meta_data infile:outfile doesn't work... neither does -map_meta_data outfile:infile, -map_meta_data 0:0, or -map_meta_data 0:0,s0 (or something like that), all of which I'd seen people suggest.

    So... I'm now looking for a command-line program (or a Python library) that can convert FLAC to ALAC on Linux, while preserving the tag data. It'd even be acceptable if I have to copy the tags after converting - but I can't find a solution for that either. I've tried QLCLI, but it seems to fail when importing Quod Libet. I'm trying to make this all work under Ubuntu. Any suggestions?

    • slhck
      slhck almost 12 years
      Can you try a more recent version of FFmpeg? You can compile it from source as documented on the homepage
    • mivk
      mivk over 11 years
      In Ubuntu 12.04 LTS, it looks like the provided version of ffmpeg does preserve the tags. I just tried ffmpeg -i "in.flac" -acodec alac "out.m4a" and all the tags seem to have been converted.