In this thread, a VLC developer says that VLC cannot play partially downloaded mp4 files because the info is stored at the end of the file. But recently when I tested the same, adding a mp4 task in Chrome and passing the partial .crdownload to VLC, it worked. VLC played the mp4 without a glitch. I didn't let the download finish and stopped the player in the middle to save bandwidth, but I believe it would have played the entire media while Chrome was still downloading it. I was also able to seek through the video, which some unfinished video formats won't allow. What to make of this? I'm doing a media streamer as a pet project and really wanna know if I can initiate the download and pass the media to vlc via command line after certain amount of bytes are downloaded.
MP4 files can have the metadata chunk at the beginning or at the end. It is usually at the end for freshly encoded files because the encoder might not know what values to write until it's done encoding the whole video (especially the parts needed for seeking).
But when preparing MP4 files for online streaming, it is common to move metadata to the beginning, e.g. as described in this blog post. (In other words, you're not the first to want to do this – it's everyday business for web browsers.)
Note: Although the post shows a full re-encode being done, I am not sure whether that is actually needed – it should be enough to just remux with
-codec copy -movflags faststart and avoid the quality loss.
There are tools you can use to see the actual structure of a given MP4 file, e.g.:
$ AtomicParsley test.m4a -T Atom ftyp @ 0 of size: 24, ends @ 24 Atom free @ 24 of size: 8, ends @ 32 Atom mdat @ 32 of size: 4038152, ends @ 4038184 Atom moov @ 4038184 of size: 58035, ends @ 4096219 Atom mvhd @ 4038192 of size: 108, ends @ 4038300 Atom trak @ 4038300 of size: 57386, ends @ 4095686 Atom tkhd @ 4038308 of size: 92, ends @ 4038400 ... Atom udta @ 4095686 of size: 533, ends @ 4096219 Atom meta @ 4095694 of size: 525, ends @ 4096219 Atom hdlr @ 4095706 of size: 33, ends @ 4095739 Atom ilst @ 4095739 of size: 279, ends @ 4096018 Atom ©nam @ 4095747 of size: 31, ends @ 4095778 ... Segmentation fault (core dumped)
mdat contains the actual audio/video data (just a single audio stream in this case) and
moov contains the metadata (e.g.
moov.udta.meta.ilst.©nam is the track title).