Log in

View Full Version : MPEG streams, and MPEG systems streams


Sohaib
28th August 2006, 13:09
Hi:

I am trying to write an MPEG1 decoder...

I was wondering if anyone knew how to parse video information from a .mpg, or .m1v or .m4v stream -- I can get info on bitrates and aspect ratio but I dont know how to read off the length of the file in frames or seconds (or milliseconds).

Also, is there a good source that I can look at online for the structure of various headers that exist in these files?

I already have core decode functions working for the most part - its just really annoying that I dont know how long a video is/might be when I start playing it.

Any help would be greatly appreciated... thanks

Sohaib
28th August 2006, 16:26
Ah... NVM... figured it out... :-)

ApPojken
29th August 2006, 16:10
Out of curiosity, what technique did you use to get the duration?

My way was to scan through the sectors of the file, count all the frames and use the frame rate to retrieve the duration. The only problem is that this takes quite a while for a 90 minute film.

foxyshadis
30th August 2006, 13:00
MPEG packets include a timestamp. By reading the last frame and comparing to the first, the duration can be obtained.

ApPojken
30th August 2006, 13:03
Thanks, can't believe I haven't thought about that. Sometimes it just is simpler than you think. :D

ApPojken
6th September 2006, 18:03
OK.. I knew it sounded to good to be true.

This only works when the timecode is not broken. For VOB files coming from a DVD these could vary. My sample was a clip where several mpeg2 files had been stiched together in the same title set.

The duration of 9 minutes could in other words not be retrieved by comparing the first GOP timestamp with the last. Without access to an IFO file the duration extraction seams impossible to do in any other way than counting the frames. Going to give the navigation pack another try but if there is no information there I give up and implement the time consuming "counting frames" scan.

Any others that has other ideas in order to optimize this?