audio - MP4 Atom Parsing - where to configure time...? -
i've written mp4 parser can read atoms in mp4 fine, , stitch them - result technically valid mp4 file quicktime can open , such, can't play audio believe timing/sampling information off. should mention i'm interested in audio.
what i'm doing trying take moov atoms/etc existing mp4, , take subset of mdat atom in file create new, smaller mp4. in doing i've altered duration
in mvhd
atom, duration in mdia
header. there no tkhd
atoms in file have edits, believe don't need alter durations there - missing?
in creating new mp4 i'm sectioning mdat
block wide box, , keeping 'mdat' header/size in right places - make sure update size new content.
now it's entirely 110% possible i'm missing crucial format, if possible i'd love final piece. got input/ideas?
code can found @ following link:
i'm going take stab in dark here , you're not updating stbl
offsets properly. @ least didn't (at first glance) see python doing anywhere.
stsc
lets start location of data. packets written file in terms of chunks, , header tells decoder each "block" of these chunks exists. stsc
table says how many items per chunk exist. first chunk
says new chunk starts. it's little confusing, @ example. saying have 100 samples per chunkk, 8th chunk. @ 8th chunk there 98 samples.
stco
that said, have track offsets of these chunks are. that's job of stco
table. so, in file chunk offset 1, or chunk offset 2, etc.
if modify data in mdat
have maintain these tables. can't chop mdat
data out, , expect decoder know do.
as if wasn't enough, have maintain sample time table (stts
) sample size table (stsz
) , if video, sync sample table (stss
).
stts
stts
says how long sample should play in units of timescale. if you're doing audio timescale 44100 or 48000 (khz).
if you've lopped off data, potentially out of sync. if values here have exact same duration though you'd ok.
stsz
stsz
says size each sample in bytes. important decoder able start @ chunk, , go through each sample size.
again, if sample sizes same you'd ok. audio tends pretty same, video stuff varies lot (with keyframes , whatnot)
stss
and last not least have stss
table says frame's keyframes. have experience aac, every audio frame considered keyframe. in case can have 1 entry describes packets.
in relation original question, time display isn't honored same way in each player. accurate way sum durations of frames in header , use total time. other players use metadata in track headers. i've found best keep values same , players happy.
if you're doing , missed in script can post sample mp4 , standalone app , can try out.
Comments
Post a Comment