30

I tried to convert a file with pacpl, but I get the well-known "256" error. With the -v flag, the FAQ of pacpl tells me:

"The file you are trying to convert is a lossless .m4a file. The format is not yet supported by FAAC/FAAD."

Since faac/faad seems to be used in every other converting tool on Ubuntu, how can I successfully convert formats?

  • How is the lossless m4a a 24 bit sample? CD's are 16 bit, and SACD's are not rippable by any means, which means it was pointlessly "upconverted" to 24 bit, which is stupid. –  Jan 29 '13 at 03:25
  • @user126919 maybe they recorded it in 24bit. – ctrl-alt-delor Dec 03 '16 at 17:31
  • I’ve converted a few lossless M4A files to FLAC before, mostly when organizing my library for compatibility with older players. The process is pretty straightforward with ffmpeg or tools like XLD on Mac. Just make sure the M4A file is truly lossless, if it’s AAC instead of ALAC, converting won’t magically make it lossless. One thing to keep in mind is that while the audio quality stays the same, some metadata might get dropped or rearranged, depending on the tool you use. I always check the output files in a tag editor after converting just to be sure everything came through right. – cipek58361 May 22 '25 at 14:39

6 Answers6

33

You can convert an m4a file to flac with the ffmpeg command-line tool:

To install ffmpeg:

sudo apt-get install ffmpeg

To convert:

ffmpeg -i filein.m4a -f flac fileout.flac

To batch convert:

for i in $(find . -type f -name "*.m4a"); do echo "Converting $i to flac"; ffmpeg -i "$i" -c:a flac "${i%.m4a}.flac"; done
karel
  • 122,695
  • 134
  • 305
  • 337
duffydack
  • 7,624
  • works for me:) Hopefully the pacpl devs will fix the problem – Simon Lenz Jan 15 '12 at 22:38
  • 2
    for file in *.m4a; do echo $file; ffmpeg -i "$file" -f flac "`basename "$file" .m4a`.flac"; done To do a batch conversion of all *.m4a files in directory. – zetdotpi Jun 13 '13 at 00:04
13
sudo aptitude install libav-tools

for file in *.m4a; do avconv -i "$file" -f flac "`basename "$file" .m4a`.flac"; done
4

While both the answers involving ffmpeg/avconv (which I think are essentially the same tool) both work, they currently have a flaw. Namely that lossless m4a is often 24 bit sample, and currently ffmpeg/avconv will generally force the conversion to end up in 16 bit sample.

I believe using sndfile-convert (libsndfile) does not have this problem. Likewise, I believe it can be avoided by using mplayer to decode the m4a before encoding it with ffmpeg or flac. I think soundKonverter on KDE may do this for you.

In any case, whatever you do, I suggest checking whether the original and the converted file have the same bit depth of samples.

SKhan
  • 41
1

Personally I use this code. for file in *.m4a; do fname=$(basename "$file" .m4a); ffmpeg -i "$file" -vn -ar 48000 -f flac "$fname".flac; done.

So the output file don't have *.m4a.flac as extension.

And this is the ouput from ffprobe on a flac file:
Stream #0:0: Audio: flac, 48000 Hz, stereo, s32 (24 bit)
And don't forget to check the tags/metadata on the file. I was surprised to see my mail address in the tag/metadata. And ffprobe show more mtag/metada as Easytag.

thanks to zetdotpi and https://stackoverflow.com/a/2664758

Jay
  • 11
  • Also, conversion from m4a to flac does seem to lose a metadata picture that was written to the files. – bomben Jun 03 '21 at 07:15
0

Just combining all the useful information from the other three answers.

To check the bit depth on your mp4 files:

# cd into desired directory then... 
ffprobe -show_streams ./[pick one file to test].m4a | grep -e codec_name -e bits_per_raw_sample 

This should show the bit depth at the bottom of the output.

To use ffmpeg and for all files in a folder (assuming they are not 24 bit (or higher)):

# cd into desired directory then... 
for file in *.m4a ; do ffmpeg -i "$file" -f flac "$( basename "$file" .m4a ).flac" ; done 

Hope that helps.

JamesIsIn
  • 309
  • 3
  • 14
0

Find all file with m4a extensions (works when filename as space or a new line) and convert codec using ffmpeg:

 find . -type f -name "*.m4a" -print0 | xargs -0 -I "{}" bash -c 'ffmpeg -i "$1" -c:a flac "${1%.m4a}.flac"' _ "{}" \;
Porcupine
  • 739