Seamless Loop Problem with Media Foundation

Survivor Young 1 Reputation point
2022-04-29T08:54:57.273+00:00

I am trying to make seamless looping video in a game engine, and I have two questions.

  1. Even though I used the Sequencer Source, I still found that the playback between two videos is not exactly seamless. I collected some logs and show in the following picture.
    197675-a.png
    Lines 1-8 is the starting of the first video segment, Line 10-25 is about the switching between the first video segment and the second video segment. Line 21 is the topology switching event, and we received frame data at Line 22, this caused about 100ms delay. All the topologies in the sequencer source share the same IMFActivate object. This object is created by MFCreateSampleGrabberSinkActivate. I don't know if any topology nodes should be shared among the topologies, such as output node. So I want to know how to kill the 100ms delay.

2) I implemented looping by appending repeated video segment to the sequencer source. Reference to the documentation, the input list can have duplicate topologies if the application called AppendTopology on the same topology more than once. So I tried appending the same topology twice, but the second one cannot be played normally. I found that I received Ended event right after Started Source event of the second topology. I tried to reuse media source instead of topology, building a different topology with same media source, but still not work. Finally, I build a brand new topology object with a brand new media source object for a same video segment, this worked for me but this is obviously very bad. So how can I reuse the topology object as the documentation said?

Thank you!

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,685 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2022-05-06T02:34:13.247+00:00

    IMFSequencerSource::AppendTopology says

    The application must indicate to the sequencer when it has queued the last topology on the Media Session. To specify the last topology, set the SequencerTopologyFlags_Last flag in the dwFlags parameter when you append the topology.

    There is a bit difference when using SequencerTopologyFlags_Last in the sample.
    Also Sequencer Source Example Code shows the IMFSequencerSource::AppendTopology usage with SequencerTopologyFlags_Last And CPlaylist::AddToPlaylist removes the "last segment" flag from the last segment when adding a new segment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.