ClementBeal / audio_metadata_reader

A pure-dart audio metadata reader
MIT License
18 stars 2 forks source link

support ftypmp42 format #11

Open PKiman opened 3 months ago

PKiman commented 3 months ago

Hi,

I found an issue with audio recordings created by Android devices. iOS is fine.

A sample file has been added to test. readMetadata.duration is null.

test/mp4/track_ftypmp42.m4a

It appears that the meta box size differs. Files with ftypmp42 header have 4 bytes meta box size. Files with ftypM4A header have 8 bytes meta box size.

At the moment only duration works. Other meta data are null for ftypmp42 files e.g. sampleRate.

https://xhelmboyx.tripod.com/formats/mp4-layout.txt

ClementBeal commented 3 months ago

Hi!

Thank you for the PR! I reviewed it and I don't notice any issue and it works! I'll try to find more mp4 to check.

With MusicBrainz, I set some metadata like the title or the album name and it works as well.

To be sure, the problem is the parsing of the ftyp was wrong, isn't it?

PKiman commented 3 months ago

Yes, there are different specs for ftyp. Some specs are ISO normed, some are proprietary (Apple). https://www.ftyps.com

This command was useful for debugging and understanding how type box parsing works.

ffprobe -v trace test/mp4/track_ftypmp42.m4a 

[file @ 0x7fdce5c04540] Setting default whitelist 'file,crypto,data'
Probing mov,mp4,m4a,3gp,3g2,mj2 score:100 size:2048
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] type:'ftyp' parent:'root' sz: 24 8 15439
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] ISO: File Type Major Brand: mp42
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] type:'moov' parent:'root' sz: 885 32 15439
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] type:'mvhd' parent:'moov' sz: 108 8 877
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] time scale = 10000
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] type:'meta' parent:'moov' sz: 118 116 877
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fdce5c04100] type:'hdlr' parent:'meta' sz: 33 8 110

https://www.file-recovery.com/m4a-signature-format.htm https://dev.to/alfg/a-quick-dive-into-mp4-57fo

PKiman commented 3 months ago

Obviously implementations use magic byte patterns and apply different specifications. There is no general method for parsing an mp4 file.

https://github.com/discord/lilliput/blob/b13db14b20fd82e580836108c73235686b6ab820/lilliput.go#L24

ClementBeal commented 3 months ago

Let's resolve the merge conflict and then I merge your PR!