Search code examples
videoffmpegvlcsambaid3

Find video resolution and video duration of remote mediafile


I want to write an program which can find some metainformation of mediafile. I'm interested in popular video formats, such as avi, mkv, mp4, mov (may be other popular too). I want basically to get:

  • Video size (720, 1080, 360 etc)
  • Total runtime of video (may be not very exact)
  • Number of audio streams
  • Name of video codec
  • Name of audio codec

There is already the mediainfo, but in my program I want to get information about remote file, which may be accessed via ftp, http, samba; or even torrent (there are some torrent solutions, which allows to read not-yet downloaded file).

MediaInfo library have no support of samba (smb://) and mkv format (for runtime).

Also, I want to know, how much data should be downloaded to get this information. I want not to download full videofile because I have no enough disk space.

Is this information in the first 1 or 10 or 100 KiloBytes of the file? Is it at predictable offset if I know the container name and total file size?

PS: Platform is Linux, Language is C/C++


Solution

  • No, you can't predictably find the information you're looking for from the "first X bytes" of the file (for any known value of X less than the full size of the media file). Some containers list all of that info in the header. Some (like QuickTime) have that metadata at the end of the file with the metadata offset in the header. Some (like AVI) list stream offsets in the header, with specific stream info in each stream's header (i.e., scattered throughout the file). And some use different styles depending on the encoding method (e.g., quick streaming vs. on-the-fly encoding).

    That said, it's theoretically possible to do what you're looking for, by requesting the appropriate byte ranges. For example, request the first 10K or so, and based on the container type, parse out which other byte ranges you'd need to read/parse in order to find the metadata. But it would be a pretty big project.