Recovering corrupted m4a recordings

Solution 1:

See here, at the bottom of the page.
Install faad if needed sudo apt install faad
dd ibs=1 skip=44 if=yourfilename.m4a of=raw.m4a
faad -a newname.m4a raw.m4a
All credits to the author of the link I am pointing to, cause I do not know what I am doing, but I tested it on your bigger file, and it works. First command takes some time. Be patient. Tried it on ubuntu 16.04.

As pointed out in the comments, the result can be opened in VLC, but not in Audacious. But we can use vlc to transcode it, or rewrite it to another format. The script below converts all *.m4a files in the current directory to *.mp3.
#!/bin/bash

quote=\"  
executable="/usr/bin/vlc"
argument3=vlc://quit

#transcoding parameters
acodecvalue=mp3
bitratevalue=128
accessvalue=file
muxvalue=raw

for x in *.m4a; do
    inputname="${x}"
    strippedname=${x%.m4a}
    outputname=${strippedname}.mp3
    quote_outputname=${quote}./${outputname}${quote}
    echo ${inputname}
    echo ${quote_outputname}
    qtranscode=#transcode{vcodec=none,acodec=$acodecvalue, # continue line !
    ab=$bitratevalue,channels=$channelsvalue}              # continue line !
    :standard{access=$accessvalue,mux=$muxvalue,dst=${quote_outputname}}
    argument1="$inputname"
    argument2=--sout=$qtranscode
    "$executable" -I dummy "$argument1" "$argument2" "$argument3"
done

Solution 2:

This works but the values use in dd are not adequate for every case. Here the author of the original post explains why: Original post of this solution

Basically you are stripping the header of the file by skipping 44 bytes with dd but that value varies from file to file, as it happened to me.

The solution is to use a hex editor (I suggest on a copy of the broken file) and delete everything from the beginning up to the end of the word "mdat". In my case it was 28 bytes instead of 44.

I use 0xED as a hex editor on mac (it's free and runs on the latest mac OS, Mojave, as of this writing). Also, for mac you can install faad using Homebrew by running

brew install faad2

You may need to specify the file sample rate if different from 44,100Hz when using faad with the switch -s

If faad returns this error Error: Maximum number of bitstream elements exceeded it could mean that you deleted too many bytes from the beginning of the file, as it happened to me at first.

Lastly, once you process the raw file with faad you will want to reencode the m4a file to make sure you have a proper and compatible file, this can easily be done with ffmpeg

ffmpeg -i newfile.m4a -c:a aac output.m4a