'Seamless Loop Problem with Media Foundation

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 as follows.
1   [2022.04.29-12:20:59:557]Session 000001B52BF8EB00:Topology 000001B4FE096960 changed status  Ready   
2   [2022.04.29-12:20:59:564]Processing New Presentation 000001B52BF8EB00   
3   [2022.04.29-12:20:59:564]Session 000001B52BF8EB00:Topology 000001B4FE096960 changed status to Started Source
4   [2022.04.29-12:20:59:629]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 66.667
5   [2022.04.29-12:20:59:662]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 100.00
6   [2022.04.29-12:20:59:696]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 133.333
7   [2022.04.29-12:20:59:729]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 166.667
8   [2022.04.29-12:20:59:771]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 200.00
9   ...
10  [2022.04.29-12:21:00:396]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 833.333 
11  [2022.04.29-12:21:00:429]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 866.667 
12  [2022.04.29-12:21:00:463]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 900.00  
13  [2022.04.29-12:21:00:496]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 933.333
14  [2022.04.29-12:21:00:525]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 966.667 
15  [2022.04.29-12:21:00:548]Session 000001B52BF8EB00:Topology 000001B5650E7480 changed status to Ready 
16  [2022.04.29-12:21:00:548]Session 000001B52BF8EB00:Topology 000001B5650E7480 changed status to Started Source    
17  [2022.04.29-12:21:00:548]Processing New Presentation 000001B52BF8EB00   
18  [2022.04.29-12:21:00:577]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 1000.00 
19  [2022.04.29-12:21:00:602]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 1033.333    
20  [2022.04.29-12:21:00:602]Session 000001B52BF8EB00: Topology 000001B4FE096960 changed status to Ended    
21  [2022.04.29-12:21:00:602]Session 000001B52BF8EB00:Topology 000001B5650E7480 changed status to Sink Switched 
22  [2022.04.29-12:21:00:693]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 1133.333    
23  [2022.04.29-12:21:00:722]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 1166.666    
24  [2022.04.29-12:21:00:768]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 1200.000
25  [2022.04.29-12:21:00:798]IMFSampleGrabberSinkCallback::OnProcessSample at Timestamp 1233.333    
26  ...

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.

  1. 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!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source