Flushing/Finalizing sink (missing audio) RRS feed

  • Question

  • Hi all,

    I've built some code that takes a webcam & mic and outputs it to the screen and to a WMV file.  The code builds a topology (based partly on the 1 Pass Windows Media Encoding tutorial) and works fine - a file is created and I can play it back.

    My issue is that I always lose about 2 seconds of audio at the end of the file (the video seems OK).  I'm assuming that it's perhaps stuck in a buffer in the pipeline somewhere and I wondered if anyone had any thoughts about how to clear this through?

    As I understand it, the MediaSink (created by MFCreateASFMediaSinkActivate) exposes the IMFFinalizableMediaSink interface which is used to Finalize the sink and finish any writing.  When IMFMediaSession::Shutdown is called, all the sinks and MFTs in the current topology are finalized automatically.  (Based partially on this.)  Is this correct?

    I've tried getting hold of the sink and finalizing it myself, had a look at MFT_MESSAGE_COMMAND_DRAIN to try and clear out the the transforms, and even tried pausing the media source, waiting a few seconds and then closing stuff down!  None of this seemed to work for me.

    Any pointers or suggestions gratefully received!

    Monday, August 1, 2011 9:52 AM

All replies

  • (p.s. I've also noticed that my encoded video has a few seconds of audio at the start which seems to happen whilst the webcam turns on - the video and audio are in sync, so the audio is additional at the start.  Perhaps this could be why the audio is missing at the end?  Any thoughts on how to try and start the audio & video at the same time?)
    Monday, August 1, 2011 10:53 AM
  • Still pretty stuck...

    Can anyone confirm that calling IMFMediaSession::Shutdown will finalize all sinks and MFTs in the topology?

    And will the finalize flush any remaining data through to the file?

    Any thoughts or comments would help me at this point!!

    Tuesday, August 2, 2011 12:43 PM
  • Last desperate attempt :-)

    Anyone have any links or info on flushing the pipeline?

    Friday, August 5, 2011 2:46 PM
  • Hi jamboharris,


    I am not an expert with MF, but I am currently working on it, so I discovered some stuffs which could help you.

    First, with your problem of additional (or missing) audio samples, are you sure all your audio samples are correctly time-stamped ?


    Secondly, with the flushing part (have a look here, maybe that will help!), have you tried a final flush of your audio samples, before the final flush (using "Finalize()" function of the sink) ?


    Hope some ideas could help you.



    Wednesday, August 10, 2011 4:31 PM
  • Thanks for the suggestions - I've had a few goes at finalizing different things in different orders, but I'll have another look with the specific ordering you suggested.

    I'm not sure if they are correctly time stamped - just did a quick Google and found a few docs on time stamps which I'll read through - do you know how best I would check to see if the output is correctly stamped?

    Thanks for the help

    Thursday, August 11, 2011 7:45 AM
  • Hi jamboharris,


    A good way to trace MF is using the event viewer in Windows. Please, have a look on this MF blog, talking about that, and showing you all you need to correctly analyse MF events (sinkwriter, mediasink, pipeline etc.). You can see that samples are time-stamped, with your index number (video or audio stream), and you can get error codes if something bad happened...
    I do not know if you will solve the problem, but looking into event viewer can help you to understand better what you did.


    I hope you will succeed and that helps.




    PS : I read you are capturing video and audio with a webcam. How are represented the input samples? Into a global file, different files (one for video and one for audio) or in media buffers?

    Friday, August 12, 2011 7:14 AM
  • Thanks again - I'll have a look through the event viewer to see if I can get some more info.


    (I'm writing the output to a single file and to the screen using MFCreateASFMediaSinkActivate, and splitting the topology for the screen with a MF_TOPOLOGY_TEE_NODE)

    Friday, August 12, 2011 7:46 AM
  • Ok, feel free to tell us whether it works well with a "good" time-stamping of samples...


    For your video and audio inputs (webcam and mic), how is the data? Stored in media buffers or does it come from files (and you read into them)?






    Friday, August 12, 2011 9:34 AM
  • Hey guys, i've had a quick look through your progess with this issue. I don't have any answers for you but have an angle you could investigate. The unique aspect of your situation is that you are using live sources for both audio and video. Two things to take note of here:

    -If you are using a transcode topology to sink the data, you are going to have adverse side-effects.

    -Live sources essentially have an infinite duration and will not fire the END OF STREAM event for your audio and video streams. I actually could be wrong about this but logically it makes sense.

    I have a feeling that if every stream doesn't fire the END OF STREAM event that the Media Session will not process all nodes correctly. I know this to be true for playback of live sources. I created my own media source for playing back a live stream. Internally I have to fire END OF STREAM from each media source stream and the Media Session shutsdown correctly by itself. Im not sure how you'd replicate this behaviour for a media source that's based on a driver interface.

    Saturday, August 20, 2011 4:26 PM
  • Hi Nobby - sorry for the late reply - It's an interesting angle that I hadn't thought of - I'll have a look at it and see what I can see






    Tuesday, September 20, 2011 8:43 AM