Skip to main content
Topic: Can ALAC file with damaged header but ok audio be saved? (Read 599 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Can ALAC file with damaged header but ok audio be saved?

Hello.

I'm new here and unfortunately I don't know much about the inner workings of audio files.
I recently discovered a number of corrupted ALAC files in my iTunes library that I can't play anymore.
In earlier/simpler cases I used ffmpeg to convert them losslessly into a new ALAC (ffmeg -i damaged.m4a fixed.m4a).
But that doesn't work with these damaged files.

Using a hexeditor and an undamaged version of one corrupted file  I could verify that the raw audio data (after the mdat) is byte-identical in both the damaged and undamaged file.

I just don't know how to save the (raw) audio data and get a new working ALAC file.

One thing I've tried and failed at is to "write" the raw audio into a new ALAC file (with a new/correct header). I've used ffmepg but it throws a lot of errors or produces a noise file.

Another idea would be to come up with some kind of general minimal header I could insert in the hexeditor before the mdat part and then adjust whatever needs adjusting. But I don't know what a header with just the bare minimum information (atoms) to make an ALAC file would look like.

There may even be more of those corrupted files in my library and maybe in the future.
So if I find a way to repair them (provided the raw audio data is intact like in this case) that would save me a lot of trouble and headache.

So if you have any idea what and how I could try that would make my day/week/month.
Thank you so much.

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #1
[...] (ffmeg -i damaged.m4a fixed.m4a).
But that doesn't work with these damaged files.[...]
ffmpeg -i damaged.m4a -c:a copy fixed.m4a
or
ffmpeg -i damaged.m4a -c:a alac fixed.m4a

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #2
[...] (ffmeg -i damaged.m4a fixed.m4a).
But that doesn't work with these damaged files.[...]
ffmpeg -i damaged.m4a -c:a copy fixed.m4a
or
ffmpeg -i damaged.m4a -c:a alac fixed.m4a
Sorry. I forgot to include that.
Actually these commands would result in failed conversions here. I had to include -vn.
So
Code: [Select]
ffmpeg -i damaged.m4a -acodec copy -vn fixed.m4a
works for some files with very minor tag problems.
In this case here, i.e. the corrupted ALAC files I found, it just gives me a - still broken - copy of the damaged files.

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #3
Have you tried other demuxers? A list here: https://www.videohelp.com/software/sections/video-de-multiplexers . Of course, some are front ends for others (or for ffmpeg) and some are probably based on others, but ...

Also, can VLC play the file? Then it should be able to demux it.
High Voltage socket-nose-avatar

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #4
Also, can VLC play the file? Then it should be able to demux it.
If you drop this file on any audio editor it will show you just the last 1:25 of 3:44. And VLC plays the whole 3:44 but there's only silence before the last 1:25.

Even though the damaged file still contains the undamaged raw audio data   any decoder that relies on the standard mp4/m4a header with the proper atoms will probably fail because the header is such a mess.

So I'm really looking for some kind of hack here to convert the raw audio data (extracted from the mdat atom) into a new playable audio file.
But as I said, I haven't managed to feed the raw ALAC audio data into something that gives me a playable audio file as output.

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #5
Tried to make a copy and rename it to .avi? VLC has a functionality for rebuilding AVI headers - there are others too. Although I've seen this renaming trick recommended, I haven't used it.
High Voltage socket-nose-avatar

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #6
Tried to make a copy and rename it to .avi? VLC has a functionality for rebuilding AVI headers - there are others too. Although I've seen this renaming trick recommended, I haven't used it.
Sorry, none of that worked. I guess the header is just too messed up. Such a bummer considering the raw audio is still good.

Do you think I could feed that ALAC encoded raw audio into VLC as a stream and get a playable audio file out of it? And if so, which settings would you recommend? I've never used VLC for such things.

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #7
I don't think VLC or something works.
To decode an ALAC file, you need to know it's global rice parameters and you need to know frame boundaries.
However, both of them are stored in the container which is damaged.

Still, I guess they are all 16bit stereo and global rice parameters are the same.
You still don't know frame boundaries, but strictly speaking it's not required.
Just feed some chunk into the decoder and let it decode a frame, then advance consumed bytes. Continue this iterative process.
You may need to skip to the next frame boundary, but it always starts with 0x20 0x00 in case of stereo ALAC, so you can search for the byte sequence.

So, it should be possible to write a custom program to do that task.

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #8
To decode an ALAC file, you need to know it's global rice parameters and you need to know frame boundaries.
However, both of them are stored in the container which is damaged.
Oh.
Is ALAC-in-MP4 really streamable then?
High Voltage socket-nose-avatar

 

Re: Can ALAC file with damaged header but ok audio be saved?

Reply #9
To decode an ALAC file, you need to know it's global rice parameters and you need to know frame boundaries.
However, both of them are stored in the container which is damaged.
Oh.
Is ALAC-in-MP4 really streamable then?

No. But if MP4 file contains only one (ALAC) track, in the mdat box ALAC frames should naturally be stuffed in a sequential order, so it's possible to decode them sequentially without container's random-access index pointing to each frame's position.

 
SimplePortal 1.0.0 RC1 © 2008-2019