osgx
osgx

Reputation: 94245

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:

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++

Upvotes: 3

Views: 3593

Answers (3)

mbklein
mbklein

Reputation: 515

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.

Upvotes: 3

James Felix Black
James Felix Black

Reputation: 300

There's simply no way to tell in the general case. It all depends on the container format of the remote file, and even then, you'll probably need to jump through a lot of hoops to get all of that metadata from even 50% of files. Restrict yourself to ISO media (QuickTime, MPEG-4, 3GPP &c.) and you can get that hit rate up higher, but even then it's non-obvious.

Upvotes: 0

Martin Beckett
Martin Beckett

Reputation: 96109

It depends on the container format, avi / mp4 / mkv

Take a look at the source to http://mediainfo.sourceforge.net/en

Upvotes: 1

Related Questions