0

I am using DirectShow for a movie playback. I modify video/audio data and render everything myself in my app. Therefore, I am using SampleGrabber filters and NULL renderers.

The problem arises when I rewind the movie (using IMediaSeeking interface) - audio significantly lags behind the video (a few seconds lag).

Movie graph with sample grabber filters

I understand the a/v sync basics and timestamps. I do understand that render filters can drop frames depending on the presentation times.

But I guess SampleGrabber filters simply receive all data? Is it possible to get audio/video data already synchronized in my SampleCB callbacks?

Dalamber
  • 1,009
  • 1
  • 12
  • 32

1 Answers1

1

On the sample grabber callback you receive data time stamped. If you keep the time stamps you get, and you make sure you have the data playback sync'ed using these time stamps in terms of playing data with equal time stamps on all streams at any time - then you will have your synchronization in good standing.

Sample grabbers receive all data, but it does not mean this data reaches grabbers in synchronized order. Matching time stamps is absolutely necessary. Because video might be temporally compressed and audio is typically not, your seeking might be getting you additional preroll data on the video leg, which you might be not processing correctly.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thank you for the explanation. I've just modified my callbacks, so I could receive current audio timestamps within my VideoCallback::SampleCB method. I simply do nothing with video frame and return S_OK if (videoEndTime < audioStartTime). Is it correct? I have tested on several files and it seems that it works better now. – Dalamber Apr 24 '14 at 19:00
  • It's up to you how to skip and match time stamps exactly, but yes you need to match time stamps on video and audio legs. – Roman R. Apr 24 '14 at 19:24