Clear accurate synchronization of subtitle files with MPEG video using DirectShow

This is a problem I've been running into for a while and haven't been able to get a good answer (even from Microsoft). I am using a generic dump filter to write compressed MPEG file files to disk. In the graph, I also have a SampleGrabber filter that gets called every frame. From the SampleGrabber callback, I get the subtitles along with the DirectShow timestamp and write them to a SAMI subtitle file (.smi). It all seems to work as the SAMI file contains the correct subtitles for each frame. However, I have several problems:

  • The first few (usually 3 or 4) DirectShow timestamps are 0. If I get callbacks from SampleGrabber, shouldn't those timestamps be incremented?

  • When I start playing, the first timestamp marked is about 10-20 subtitles per SAMI file. I am assuming the first frame will display the first timestamp in the file.

  • This is probably related to C # 2, but the subtitles are out of sync with the corresponding frames in the file. Sometimes they can be up to 40 frames.

I am using DirectShow via C ++, grabbing Hauppauge HVR-1800 under Windows XP SP3 (with latest drivers 09/08/2008) and playing in Media Player Classic 6.4.9.0. Any ideas are appreciated.

+1


source to share


1 answer


Whether you are using getting incoming IMediaSample GetTime or GetMediaTime. GetTime is what you want as it displays the presentation times of streams.

Be sure to check the incoming function IMediaSample isPreRoll . Parting patterns should be ignored as they will be output again during playback. Another thing I would like to do is make sure your sample grabber is as far down your filter as possible. Preferably after any demuxer and render.



Also see the article on TimeStamps in the DirectShow documentation. It sets out other caveats about the use of timestamps.

Of course, even after all the tips above, there is still no absolute guarantee of how a particular DirectShow filter will perform.

+2


source







All Articles