Log in

View Full Version : determining the length (time) of a mpeg video?


moogie
1st December 2004, 06:46
I am not sure which forum this question is best suited for...

I am needing to determine the length of a mpeg 1 and mpeg 2 video clips and have not had any luck finding appropriate information on the net.

It seems that the mpeg file format does not include any information in the header for determining the length of a mpeg video clip without actually 'running' though the video first... is this correct? if so (or even if not) how would one go about determining the length of a clip?

Nic
1st December 2004, 10:23
I asked a very similar question to this a long time ago:
http://forum.doom9.org/showthread.php?s=&threadid=14465

The only exact way to know how long a MPEG file is, is to search and count each frame (and also pay attention to the repeat first field flag in MPEG-2). And that is a long winded process.

Any other way (like checking the first and last PTSs/GOPs or guessing by bitrate) doesn't work (very accurately) on most files you'll come across.

-Nic

moogie
2nd December 2004, 00:24
Ah, cheers...

who would have thought that such a commonly required statistic is not supplied in the MPEG format ?!

fccHandler
3rd December 2004, 00:10
That's because MPEGs are "streams." As an analogy, think of a live television broadcast. In theory, it has no definite beginning nor ending, and you can jump in at any time and begin viewing the program contents.

MPEGs do have a lot of embedded timing information, which tells you the current time at any given moment throughout the stream. But as others have noted, attempting to use this information to guess the total duration of an encapsulated MPEG file is very tricky and often unreliable.