簡介
MP4只是一種container,可以想像成容器,裡面可以放mp3或aac等音樂。
關於MP4格式的spec可以在這裡下載。
Library
關於MP4檔案的操作,已經有現成的library可以使用囉~
https://code.google.com/p/mp4v2/
觀察MP4格式的工具
可以藉由atomicparsley這個工具來印出MP4檔案的內部結構
brew install atomicparsley
atomicparsley /path/to/mp4 -T 1
印出來的結果像這樣
Atom ftyp @ 0 of size: 24, ends @ 24
Atom moov @ 24 of size: 569, ends @ 593
Atom mvhd @ 32 of size: 108, ends @ 140
Atom iods @ 140 of size: 24, ends @ 164
Atom trak @ 164 of size: 429, ends @ 593
Atom tkhd @ 172 of size: 92, ends @ 264
Atom mdia @ 264 of size: 329, ends @ 593
Atom mdhd @ 272 of size: 32, ends @ 304
Atom hdlr @ 304 of size: 33, ends @ 337
Atom minf @ 337 of size: 256, ends @ 593
Atom smhd @ 345 of size: 16, ends @ 361
Atom dinf @ 361 of size: 36, ends @ 397
Atom dref @ 369 of size: 28, ends @ 397
Atom url @ 385 of size: 12, ends @ 397
Atom stbl @ 397 of size: 196, ends @ 593
Atom stsd @ 405 of size: 96, ends @ 501
Atom mp4a @ 421 of size: 80, ends @ 501
Atom esds @ 457 of size: 44, ends @ 501
Atom stts @ 501 of size: 24, ends @ 525
Atom stsz @ 525 of size: 20, ends @ 545
Atom stsc @ 545 of size: 28, ends @ 573
Atom stco @ 573 of size: 20, ends @ 593
Atom mdat @ 593 of size: 9, ends @ 602
------------------------------------------------------
Total size: 602 bytes; 22 atoms total.
Media data: 0 bytes; 602 bytes all other atoms (100.000% atom overhead).
Total free atom space: 0 bytes; 0.000% waste.
------------------------------------------------------
AtomicParsley version: 0.9.6 (utf8)
------------------------------------------------------
Movie duration: 7504.597 seconds (02:05:04.60) - 0.00* kbp/sec bitrate (*=approximate)
Low-level details. Total tracks: 1
Trk Type Handler Kind Lang Bytes
1 soun [none listed] mp4a und 1
0.00* kbp/s 7504.597 sec MPEG-4 Unknown profile: 0x0 channels: (2)
這個用python寫的工具也是不錯的選擇
https://github.com/amarghosh/mp4viewer