locked
Multi-threaded use of SinkWriter (or equivalent)

    Question

  • Hi,

    I would like to save generated bitmaps to a video file. I have IMFSinkWiter working perfectly well, but I am only using two threads (one to generate the frames, and the second to write them to the file via IMFSinkWriter. Is there a way to use more than one thread for the output to the video file if the machine has a multi-core CPU? Adding more threads for frame generation is not my problem - the slowest operation is writing them to the output file.  From my experiments IMFMediaSink does not deal with the case of adding frames to the output in anything other than the sequence they are presented to the API. The API works, but the video file is written out of order.

    So IMFSinkWiter works perfectly well for the simple case of using one thread for output, should I use another media foundation component to process frames for output in batches or interleve them somehow? Or should IMFSinkWiter  work perfectly well if you write the frames out of order from multiple threads & I have some other issue to track down?

    Wednesday, March 20, 2013 5:12 PM

All replies

  • Hi,

    Media Foundation can use asynchronous calls, which is the similar with Multi-threaded. There is a work queues will help you to do the threads synchronization.

    You don't need more codes to control this.
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms705623(v=vs.85).aspx

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 22, 2013 3:32 AM
    Moderator
  • I marked my reply as answer, if your issue has not been solved please unmark it and update more information about this issue.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 27, 2013 1:34 AM
    Moderator
  • Thanks for your help. I have looked at this API, and I don't think it solves the problem. If I serialize the output, I will only ever have one asynch method running at a time, which is no faster than what I have. if I don't serialise output, I will have multiple overlapping calls to IMFSinkWiter, which at least according to my experience cannot deal with out-of-sequence output - so my frames will get mixed up in the output file. What I really want is to have a couple of threads running, which will easily max out the disk, and to be able to provide frames to the MF API in a non-serialised way.
    Wednesday, March 27, 2013 10:19 PM