Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many bytes does ffprobe need?

Tags:

ffprobe

I would like to use ffprobe to look at the information of media files. However, the files are not on my local disk, and I have to read from a remote storage. I can read the first n bytes, write them to a temporary file and use ffprobe to read the information. I would like to know the least such n.

I tested with a few files, and 512KB worked with all the files that I tested. However, I am not sure if that will work for all media files.

like image 217
W. Zhu Avatar asked Oct 19 '25 02:10

W. Zhu


2 Answers

ffprobe (and ffmpeg) aims to parse two things when opening an input:

  1. the input container's header
  2. payload data from each stream, enough to ascertain salient stream parameters like codec attributes and frame rate.

The header size is generally proportional to the number of packets in the file i.e. a 3 hour MP4 file will have a larger header than a 3 min MP4. (if the header is at the end of the file, then access to the first 512 kB won't help)

From each stream, ffmpeg will decode packets till its stream attributes have been populated. The amount of bytes consumed will depend on stream bitrate, and how many streams are present.

So, the strict response to 'I am not sure if that will work for all media files' is it won't.

like image 143
Gyan Avatar answered Oct 21 '25 18:10

Gyan


In a nutshell: ffprobe the beginning, then the end, then the full file.

I faced the same problem and solved it with a loop:

  1. I get the first bytes until ffprobe returns a 0 exit code (important to append new bytes to already fetched ones).
  2. If after 1024 bytes from the start there is no valid result, I start again from the end of the file.
  3. If after 1024 bytes from the end there is still nothing I consider that the file is a "hard case" and download it fully to apply ffprobe over it.

I found 512 bytes to be quite enough, where the headers are.

like image 37
Jorgu Avatar answered Oct 21 '25 16:10

Jorgu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!