locked
MFCreateMediaSession supported in Store apps?

    Question

  • I'm working on a Store app where I want to merge an audio file and a video file using Media Foundation. I have a working sample for a desktop app which uses functions like MFCreateMediaSession and MFCreateTranscodeTopology. For the Windows Store app I am creating a C++ component with the Windows Runtime Component template and I am trying to migrate my existing code.

    But now I get the error that the functions MFCreateMediaSession and MFCreateTranscodeTopology are not defined. Are these functions not supported in Windows Store apps? If not, why not, and is there a way to transcode files in an other way?

    Thanks in advance!

    Ronald

    Thursday, January 10, 2013 12:44 PM

Answers

  • I managed to get something working. I used a sourcereader and a sinkwriter. When first processing the entire audio stream and then the video stream, the process seems to hang. When I synchronize the two streams by looking at the timestamp of each sample, it works.

    Note : I changed the process as described above. I am not getting the video samples from a file, but I create them in code through the MFCreateSample function. The audio sample are coming from a sourcereader/file.

    1. Create SourceReader from audio file.

    2. Set MediaType on the stream coming out of sourcereader through SetCurrentMediaType method. I guess the SourceReader contains a decoder.

    3. Create SinkWriter

    4. Create MediaType as it is going into the SinkWriter. Should have the same attributes as the MediaType coming out of SourceReader, set in step 2.

    5. Create MediaType as it is coming out of the SinkWriter (which in my case is writing to a file).

    6. Add stream to SinkWriter with MediaType from Step 5 with AddStream method.

    7. Call SetInputMediaType in SinkWriter with MediaType from step 4.

    8. Do step 4 - 7 for video stream

    9. Call BeginWriting method on SinkWriter

    10. Call ReadSample on SourceReader to get sample and call WriteSample on SinkWriter to write that sample to SinkWriter

    11. Check timestamp of audio sample, and if nescessary create a video sample (in my case through code) and write it to the SinkWriter

    12. Do step 10 - 11 untill there are no more audio samples left

    13. Call Finalize method on SinkWriter

    Ronald

    Saturday, January 12, 2013 1:47 PM

All replies

  • Hi

    Here are two options for you:

    1) Use WASAPI and pump your synthesized PCM audio directly to the audio manager (preferred)

    2) Create a custom source that can plug into the Media Foundation Media Engine

    Either approach will work as expected. You will need to carefully review each method and compare them against your software requirements. For most synthesized audio scenarios, using the WASAPI is recommended.

    Win32 and COM for Metro style apps (multimedia)
    http://msdn.microsoft.com/en-us/library/windows/apps/hh452756.aspx

    Please check this thread
    http://social.msdn.microsoft.com/Forums/hr-HR/winappswithnativecode/thread/fa0000e2-9969-42d8-9a2e-aa5684689ade

    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, January 11, 2013 6:20 AM
  • Jesse,

    Thanks for answering, but these links do not help me because it seems that these are only about capturing audio. The requirement is that I have to merge two existing files, where one contains an audio stream, and the other a video stream.

    If I use sourcereaders and sinkwriters would that be the good approach? If yes, can I first process the video file and then the audio file? Or do I have synchronize the reading and writing, meaning whichever source has the earliest sample, write that to the sinkwriter, and repeat that process untill both video and audio file have no more samples left.

    Anyone any experience with this, or know about a working sample?

    Thanks in advance!

    Ronald

    Friday, January 11, 2013 9:07 AM
  • I managed to get something working. I used a sourcereader and a sinkwriter. When first processing the entire audio stream and then the video stream, the process seems to hang. When I synchronize the two streams by looking at the timestamp of each sample, it works.

    Note : I changed the process as described above. I am not getting the video samples from a file, but I create them in code through the MFCreateSample function. The audio sample are coming from a sourcereader/file.

    1. Create SourceReader from audio file.

    2. Set MediaType on the stream coming out of sourcereader through SetCurrentMediaType method. I guess the SourceReader contains a decoder.

    3. Create SinkWriter

    4. Create MediaType as it is going into the SinkWriter. Should have the same attributes as the MediaType coming out of SourceReader, set in step 2.

    5. Create MediaType as it is coming out of the SinkWriter (which in my case is writing to a file).

    6. Add stream to SinkWriter with MediaType from Step 5 with AddStream method.

    7. Call SetInputMediaType in SinkWriter with MediaType from step 4.

    8. Do step 4 - 7 for video stream

    9. Call BeginWriting method on SinkWriter

    10. Call ReadSample on SourceReader to get sample and call WriteSample on SinkWriter to write that sample to SinkWriter

    11. Check timestamp of audio sample, and if nescessary create a video sample (in my case through code) and write it to the SinkWriter

    12. Do step 10 - 11 untill there are no more audio samples left

    13. Call Finalize method on SinkWriter

    Ronald

    Saturday, January 12, 2013 1:47 PM