Opened 4 years ago

Last modified 22 months ago

#9140 open defect

aac gapless fail

Reported by: Guy Sivey Owned by:
Priority: normal Component: ffmpeg
Version: unspecified Keywords: aac gapless
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
I would like to be able to play all aac audio files (.m4a) gaplessly , i.e. without gaps or other interruptions.

Occasionally, the transition from one file to another is not smooth, and I am supplying sample media where this is the case.

I am submitting the 2 files referenced below, along with more details in "aacGaplessFail.txt".

Version unknown, because I am experiencing this via mpd which uses an ffmpeg decoder plugin with unknown origin. Reproducing quote below supplied by mpd developer.

How to reproduce:

ffmpeg -f concat -safe 0 -i concat.txt -c copy out.m4a

... where concat.txt contains:

file '01 Track01 aac gapless fail.m4a'
file '02 Track02 aac gapless fail.m4a'

When I played out.m4a, I heard the same glitch as with MPD

Attachments (1)

aacGaplessFail.txt (1.2 KB ) - added by Guy Sivey 4 years ago.
aac gapless fail text - 2 media files to follow, size 6MB combined

Download all attachments as: .zip

Change History (12)

by Guy Sivey, 4 years ago

Attachment: aacGaplessFail.txt added

aac gapless fail text - 2 media files to follow, size 6MB combined

comment:1 by Guy Sivey, 4 years ago

I think I am supposed to wait to be invited to submit my sample media. It consists of 2 files size 6MB in total.

comment:2 by Elon Musk, 3 years ago

Resolution: needs_more_info
Status: newclosed

Concating gapless audio at (de)muxer level does not work almost always.

Also you can upload files on some upload service and provide such links here.

Closing for now as no samples provided.

comment:3 by Guy Sivey, 3 years ago

Resolution: needs_more_info
Status: closedreopened

I have discontinued use of ffmpeg and purchased a commercial product which had this problem, and they are releasing new firmware to fix it. Ffmpeg still has the problem, and if you want to fix it, examples which display this characteristic can be found here:-
https://www.dropbox.com/s/jdxm0hcsaobgz8z/AACgaplessFail.zip?dl=0
or here:-
https://drive.google.com/open?id=1HrSpvhKWE8_5BjT6yNVVsOIV04CBZryk
Cheers,
Guy

Last edited 3 years ago by Guy Sivey (previous) (diff)

comment:4 by Elon Musk, 3 years ago

Hmm, those files does not have edit list atom at all so how they are supposed to support that?

comment:5 by Guy Sivey, 3 years ago

Sorry, I don't know what you mean. I am providing this information for your benefit, in case you might want to improve ffmpeg. The history which leads me to think that there is a problem with ffmpeg is as follows:-

  • The uploaded m4a/aac files are made with iTunes on a Windows PC, from edited WAV files.
  • These m4a/aac files play continuously with no gap when played with foobar2000 on a Windows PC, but there is an audible gap when they are played with mpd on a Raspberry Pi with Raspbian.
  • I referred this to the developer of mpd, who claims that, using the commands shown, he proved that the problem is with ffmpeg. He did not indicate which version of ffmpeg he used.

So I have referred his findings to ffmpeg for further investigation. Since I have discontinued use of mpd, it is of limited interest to me whether you follow this up or not. I just thought it might help if I reported it.

Regards,
Guy

comment:6 by Elon Musk, 3 years ago

That files can not be decoded without gaps because nothing signals full duration in number of samples. But I managed to find nonbroken files already and reproduced the bug you tried to report here.

comment:7 by Balling, 3 years ago

The uploaded m4a/aac files are made with iTunes on a Windows PC,

Ffmpeg does not support iTunSMPB tag, seamless playback, that Itunes uses, even for mp3 sound (at least here patches are on mailing list https://patchwork.ffmpeg.org/project/ffmpeg/list/?q=Gapless&order=date )!!

Only the new way with editlists and those only work in mp4 AND also AFAIK at least for EAC3 there is no removal of trailing samples...

iTunSMPB will remove those too.

For example, your first file 01 Track01 aac gapless fail.m4a

has

iTunSMPB        :  00000000 00000840 0000001C 00000000001A5FA4 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

that means 2112 samples (0x840) should be skipped in the beginning and 28 (0x1c) in the end, leaving you with 1 728 420 samples (0x1A5FA4). As for next they are not used in aac, in mp3 there is also a sync field. Also, AAC HC needs to do x2 on those.

Last edited 3 years ago by Balling (previous) (diff)

in reply to:  7 comment:8 by Guy Sivey, 3 years ago

Replying to Balling:

Ffmpeg does not support iTunSMPB tag

Thanks for that information, Balling. I don't understand all of what you said, but I understand that iTunes creates mp3/m4a files which are not fully supported by ffmpeg, which is a bit of a shock to me. I am guessing that ffmpeg supports some kind of industry standard for making mp3/m4a(aac) gapless work, and that it is Apple who is out of line. How can I identify if my files follow this standard, and is there a recommended encoder which will follow this standard? LAME for mp3, I guess, but what for aac?
Regards,
Marmite

comment:9 by Balling, 3 years ago

identify if my files follow this standard

Any command ffplay, ffmpeg will show metadata iTunSMPB. As to how to edit, I recommend Audacity, of course. Just see what amount of samples you should delete from both sides.

some kind of industry standard for making mp3/m4a(aac) gapless work

Yes, you can use an editlist to remove 256 samples (that is what is written BTW, not timestamp) for eac3 sound, but you will have to remove 11 ms from the end for eac3. Same for aac, yet the samples are from iTunSMPB. As for concat, it should work with longer editlist. There is also a way to use PTS (presentation timestamps) for mkv or TS yet those will not be perfectly 256, for example, so IMHO, bad.

that it is Apple who is out of line

Apple came first! ISO standard for AAC using edts + sgpd atoms and LAME way for gapless mp3 came after that.

Last edited 3 years ago by Balling (previous) (diff)

comment:10 by Balling, 3 years ago

Status: reopenedopen

Okay, I have a question to Paul/Elon. Why editlist's media duration is not applied while editlist's media time is applied??? This is this bug: https://bugs.chromium.org/p/chromium/issues/detail?id=668999

Generate

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -c:a aac outaaceditlist.mp4

that will have (Mediainfo cannot parse sgpd and sbgp yet)

AB1F      Track duration:                    5000 (0x00001388) - 5000 (0x1388) ms
AB23      Media time:                        1024 (0x00000400) - 1024 (0x400) 
AB27      Media rate:                        65536 (0x00010000) - 1.000

B00A      sgpd (26 bytes)
B00A       Header (8 bytes)
B00A        Size:                            26 (0x0000001A)
B00E        Name:                            sgpd
B012       Unknown:                          (18 bytes)
B024      sbgp (28 bytes)
B024       Header (8 bytes)
B024        Size:                            28 (0x0000001C)
B028        Name:                            sbgp
B02C       Unknown:                          (20 bytes)

Yet when decoded it has 5000 not applied (and it is a problem, since aac past 5000 ms (1024 dropped priming samples from the start are not counted there) has actually some garbage there, not total silence)!!! So 683 samples are to be dropped (not counting that sample on 5 seconds perfectly).

ffmpeg -i outaaceditlist.mp4 coolaac5ms.wav

At least sgpd / sbgp is being applied. Those atoms say that decoding should happen from -1 sample so not dropping 1024 samples but dropping 1023 then decoding 1 then dropping it and applying its MDCT to next sample so that it is correct.

Last edited 3 years ago by Balling (previous) (diff)

comment:11 by Balling, 22 months ago

This now caused https://bugzilla.mozilla.org/show_bug.cgi?id=1703812 (two regressions in the end).

Note: See TracTickets for help on using tickets.