While recording is in progress, the .mp4
file contains ftyp
and wide
atoms, followed by an mdat
atom where video/audio data are appended. The mdat
atom does not yet have its size
or type
fields set.
The .mp4.tmp
file contains a Wowza-specific format used to store stbl
(sample table) entries that can be appended to while recording. Each entry in this file has a 4-byte type
field (stsz
, stts
, stsc
, stco
or stss
), followed by a 4-byte size
field, followed by size
bytes of data (the bytes used by the type
/size
fields are not included in the value of the size
field). This format is based on files I created with Wowza 4.1.2, and may change with new Wowza versions.
I also had a known good .mp4
file created by Wowza from the same input source to use as a reference.
To create a working .mp4
file, I set the size
field of the mdat
atom to the number of bytes remaining in the .mp4
file and the type
field to mdat
, then appended a moov
atom built from atoms in the known good file and the sample table entries in the .mp4.tmp
file.
The sample table entries in the .mp4.tmp
file don't indicate whether they apply to the video or audio tracks, so it took some guesswork based on average sample size, average samples per chunk, and order written into the .mp4.tmp
file to determine how to map these entries to tracks. Since the recording was interrupted, not all of the sample tables indicated the same number of samples were present, so I truncated the longer ones.
Apple's QuickTime File Format docs provided a good reference for the structure of the atoms I needed to recreate to get a working file.