none
Seamless looping in MediaFoundation

    Question

  • Very simple task yet almost impossible to achieve in MediaFoundation. I've seen the question asked with no answer. The solution I have right now is to call Start when I get MEEndOfPresentation but that will skip a couple frames at the end of the video. Any better solutions?

    Wednesday, March 23, 2011 2:24 AM

All replies

  • The only way to get seamless behavior is using the sequencer source.  The sequencer source sends MENewPresentation and MEEndOfPresentationSegment events which cleanly preroll and start the next presentation while the current presentation is ending.  In order of the transition to be seamless, the sink nodes need to be the same between topologies. 
    Wednesday, April 27, 2011 9:51 PM
    Moderator
  • I mean seamless looping of a single clip.

    The drawback with the sequencer source is that you have to know ahead of time the order in which your videos will play. Let's say you want to play clip "A" in a loop and when an external event is fired in your app you want to switch to clip "B", "C" or "D". If the order you queued your topologies in the sequencer source is A, B, C, D then a transition from A to C won't be seamless.

    Thursday, May 12, 2011 6:42 PM
  • The only way to do seamless looping would be a sequencer source with the same element repeated in the sequence, or a similarly behaving custom source.

    The sequencer source supports adding and removing elements while streaming, as well as seeking to arbitrary elements within the sequence.  If you are making the modifications right at the moment when the element transition is supposed to occur then glitches are possible, but otherwise it should be seamless.

    Wednesday, June 22, 2011 10:14 PM
    Moderator
  • Might be a bit late, but there's a more simple solution for this.

    I handle exactly this in the OnPresentationEnded Event of my media session. I had trouble when I just called the Start() function for seeking (which resulted in skipping few frames and freezing completely after 2-3 loops), but when I called Pause() before seeking everything worked like a charme.

     

     

    //Pause the media session before seeking
    m_pSession->Pause();
    m_state = Paused;
    
    //Create variant for seeking information
    PROPVARIANT varStart;
    PropVariantInit(&varStart);
    varStart.vt = VT_I8;
    varStart.hVal.QuadPart = 0; //i.e. seeking to the beginning
    
    //Start media session again
    m_pSession->Start(&GUID_NULL,&varStart);
    m_state = Started;
    PropVariantClear(&varStart);
    


    Using that I had some loops running over days without freezing, frame skipping or whatever!

    Offtopic: Combined with AlphaImageOverlay and a hardware DMX interface, you can do pretty things for professional stage productions...

     


    • Edited by msfuture Saturday, October 08, 2011 11:03 PM
    • Proposed as answer by Guy Godin Wednesday, January 25, 2012 9:37 PM
    Saturday, October 08, 2011 11:01 PM
  • Tried this and the video still freezes after the 2nd loop.
    However if I debug and put a breakpoint there (to try and fix the problem), it works an infinite number of times without issue.
    Friday, November 07, 2014 7:57 PM