Re: Problems with MPEG2 duration and frame-by-frame navigation

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
.



Relevant Pages

  • Re: How PowerDVD works fine with Mpeg2 Video Duration ?
    ... format). ... If I separately distribute those video files, ... just now i am expolring ur filters for the mpeg2 files what i have in ... Mpeg2Splitter) are giving correct duration with ur mpegsplitter.ax ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Duration wrong (too short) when playing mpgs in WMP 10 and 11
    ... The duration is always about 20% of the actual duration. ... video ffdshow Video Decoder ffdshow.ax 1.0.4.1518 ... video CyberLink Video/SP Decoder CLVSD.ax 8.0.0.1828 ... though HD .tivo files play fine that I bring in from my Tivo HD, ...
    (microsoft.public.windowsmedia.player)
  • AudioVideoPlayback - Attempted to access an unloaded AppDomain.
    ... In my asp.net application I upload a video file and then need to get the ... duration and other properties. ... I get "Attempted to access an unloaded AppDomain" when I instanciate the ... strDuration, Double& Duration, Int32& intWidth, Int32& intHeight, String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Duration wrong (too short) when playing mpgs in WMP 10 and 11
    ... video ffdshow Video Decoder ffdshow.ax 1.0.4.1518 ... video CyberLink Video/SP Decoder CLVSD.ax 8.0.0.1828 ... video Nero Video Decoder NeVideo.ax 3.2.0.30 ...
    (microsoft.public.windowsmedia.player)
  • Remove transition between two video in a playlist
    ... duration of 30 minutes each and no frame is lost between two successive ... I want to see one hour of video, so I create a playlist which contains two ...
    (microsoft.public.windowsmedia.sdk)