Re: Problems with MPEG2 duration and frame-by-frame navigation
- From: Geraint Davies <geraintd@xxxxxxxxxx>
- Date: Thu, 27 Oct 2005 10:15:08 +0100
On Fri, 21 Oct 2005 14:05:06 -0700, Joe Flynn wrote:
> "Sensei76" wrote:
>
>> Videos show wrong duration
>> Hello, I need help with the following problem, please.
>>
>> I am using C# and DirectX 9 to show MPEG-2 video files within a Windows
>> form. Unfortunatelly I often do not get the correct duration of the file when
>> checking the "duration" property, e.g. a 18 second clip assumes to be only 4
>> seconds long. So all these videos stop playing too early.
>>
>> Also, it is not possible to jump to certain positions in the video. If I add
>> a new value (e.g. "AverageFrameLength") to the "CurrentPosition" the
>> displayed video proceeds only every n-th frame and skips all frames in
>> between.
>>
>> I did not have these problems with a MPEG-1 video, for example. With those,
>> everything worked fine.
>>
>> Does anyone have an idea, why the durations are gathered incorrectly and how
>> I handle this? I searched the whole web for a solution, but it seems nobody
>> else has ever had a problem like this.
>>
>> It seems that there are two things that seem have an influence on this
>> situation.
>>
>> 1.) If these video files are converted to use a constant bit rate the
>> duration property seems to get at least get the correct value. Moving from
>> frame to frame still does not work reliably. But as conversion of all files
>> increases their sizes significantly, this ist not an option anyway.
>>
>> 2.) Also, this does not work with every MPEG-2 codec. To receive correct
>> duration values, I first needed to remove the "Moonlight Elecard" MPEG-2
>> Codec from my system. After that it used another codec automatically. In my
>> case this is the "MPEG-2 Demultiplexer" (Which - I guess - belongs to the
>> DirectX installtion).
>> Of course, I cannot know what codecs might be installed on a destination
>> system for my application, and even worse, I cannot simply remove a codec
>> from the system just because my app does not like it...
>>
>> Any ideas for a workaround?
>
>
> The MPEG VBR duration problem has been discussed here at various times in
> the past - a Google Groups search should yield some hits. Basically, since
> MPEG is not an indexed encoding format a correct determination of the stream
> duration will always be somewhat problematic. The MPEG splitter filter
> typically employs some form of heuristic technique to calculate the duration
> which typically consists of using the bit rate and the byte size of the file.
> Because VBR encoded files can have varying bit rates this method can yield
> large errors. If need to know the exact duration for the clip the only
> certain way of doing this would be to scan the file counting the number of
> frames and then use the frame count and the frame rate values to determine
> the stream length. Of course this method is also very slow.
>
> Also, if you want to explicitly use a particular filter in your graph - ie
> the Microsoft Demux rather than another one that may have a higher merit like
> the Moonlight one - you can simply preload your graph with the desired
> filter. Then Intelligent Connect should use that filter when it builds the
> graph.
>
>
> Joe Flynn
You're right, VBR is difficult and there are no completely correct
solutions short of indexing the whole file. In my code I've calculated the
duration by subtracting the first pts from the last pts in the file, and
then checking that against the file size / mux rate estimate to see if the
PTS values have wrapped around. This won't help particularly if there is a
PTS discontinuity in the file, however.
Then, when seeking to a location, I make an estimate based on the overall
bitrate, jump to that location and find a PTS. If this PTS is not
acceptable, make a new estimate based on the local bitrate and jump again.
You can see this logic in the mpeg-1 parser on my web site. Converting this
to work with mpeg-2 PS would be very simple.
G
.
- Prev by Date: Re: How can I replace the system wmv source filter with my own?
- Next by Date: Re: Issue after pause and resume for higher Data rate only
- Previous by thread: Re: Problems with MPEG2 duration and frame-by-frame navigation
- Next by thread: custom video filter in DES timeline
- Index(es):
Relevant Pages
|