On Thu, 1 May 2008, Thomas Richards wrote:

> I'm attempting to write a small application that extracts the durations
> from MPEG2 files. I've been looking at the documentation and the
> samples, and have come up with a simple app that calls "mpeg2_parse()"
> until it returns "STATE_GOP", and when it does, looks at the
> "info->gop->*" members.
>
> I have two small problems:
>
> The first is that the gop information seems to be the current position
> in the stream, which means that the only way I can read the entire
> stream length is to read the entire file, and save the last result.
>
> The second problem I have is that some files don't seem to have a GOP
> section.
>
> Is the total stream duration stored somewhere in the file? If so, is
> there an easy method to extract it?

Hi Thomas,

You will have to read the entire file (or at least until a Sequence end 
code), if you want this to work on MPEG-2 video elementary streams or 
MPEG-2 system streams.

The reason is that MPEG-2 really specifies a syntax for video streams or 
sequences -- think an HDTV broadcast that goes on forever. There's no 
notion of a "file" in the specification. Some non-MPEG-2 container 
formats, obviously, do have a notion of "file" and total duration.

I believe the only real way to do it is to count up the number of frames 
and multiply by the frame rate given in the Sequence header.

You can't rely on the GOP header -- it's optional.

Hope this helps.

Best,
Keith

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Libmpeg2-devel mailing list
Libmpeg2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmpeg2-devel

Reply via email to