0

I need to refresh metadata for large mp4 files in a database, I don't want to download the hole file to get the frame rate and resolution.

By experimentation I found that downloading only 1MB will suffice for ffmpeg -i to show me the info.

Can you point me to documentation that explains this?

Calin
  • 6,661
  • 7
  • 49
  • 80

1 Answers1

1

This answer points out that the MP4 file header size really depends on a number of factors, like:

  • number of tracks
  • the H.264 encoding properties
  • some muxers put their names into remaining free space ("atoms" - see link above)

As stated in the linked answer, you can expect the header to be from 1 to 4 kBytes large.

Since one megabyte is a comparably small amount of data nowadays (considering only a small amount of files - it may be different for you), you are very safe if you fetch the first megabyte only (1 MByte = 1024 KByte).

If you can stream the data you are getting and constantly check the bytes, you can listen for the character sequence mdat, as stated in the linked answer (again). It should denote that the file header is probably over.

Community
  • 1
  • 1
randers
  • 5,031
  • 5
  • 37
  • 64
  • This is a really bad way to do it. The real answer is to start download the file and parse it. The first 4 bytes of each atom are the type, the next 4 are the size. once you find an atom type of 'moov' the next 4 bytes tell you EXACTLY how many more byte to download. – szatmary Nov 30 '15 at 18:46
  • @szatmary I mainly did a "link-only answer", but I also quoted the main parts of the link since it's the recommended way of doing it. I have pretty much next to no knowledge about the topic, and I stand corrected. Feel free to post a corrected version of my answer. – randers Nov 30 '15 at 18:50