How to read Mdat atoms of a mp4 video?
Asked Answered
J

1

6

I am trying to parse a mp4 and able to do parse moov but not sure how to use moov information to parse mdat.

My goal is to get the track info like metadata and if possible frames from mdat as it contains the video and audio data.

currently following QuickTime File Format Specification

Tried with Sample-to-Chunk Atoms but all my stsc (20 bytes) looks like this:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0]
[0 0 0 1]
[0 0 0 1 0 0 0 1]
[0 0 0 1]
    fmt.Println(binary.BigEndian.Uint32(buf[0:4])) //4
    fmt.Println(binary.BigEndian.Uint32(buf[4:8])) //4
    fmt.Println(binary.BigEndian.Uint32(buf[8:16])) //8
    fmt.Println(binary.BigEndian.Uint32(buf[16:20])) //4

Don't know currently how to approach and parse mdat atoms.

Any help would be appreciated!

Julissajulita answered 26/3, 2022 at 19:27 Comment(3)
Did you try this lib? pkg.go.dev/github.com/abema/go-mp4Bigham
If not you can try to define your structures and use this to parse: nicedoc.io/ghostiam/binstructBigham
@Julissajulita Try reading as buf[0:3] and buf[4:7] etc...? Your first four bytes are [0] [1] [2] [3] so why read up to [4]?Finesse
P
0

the mp4 specification is ISO/IEC 14496-12 which is more definitive than the qt one.

If you want to understand how the sample tables reference individual frames you could look at my project here https://github.com/essential61/mp4analyser

Psychodiagnostics answered 4/8, 2022 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.