locked
Any way to control MediaTranscoder while it requesting samples from MediaStreamSource ?

    Question

  • I'm developing a video editing app what lets to join several video files. I found good APIs for that MediaTranscoder and MediaStreamSource  .

    I'm initializing transcoding with mediasource , on every sample request i'm reading sample from media file and providing it to sample request. Everything works fine on a single file.

    Now i want to join two files. On sampleRequest i'm checking if current media file reached end of stream and if so i'm opening next file.

    The problem - transcoder requesting audio and video samples not in parallel and not sequentially.  So stream reach end of stream on audio stream while video stream still has samples.

    With my method i could return sample=null for audio if it reached EOS and provide rest of video samples, but after sample=null transcoder stops to requesting audio samples at all. So my next media file will be joined to clip w\o audio. 

    Or i can check what stream reached EOS first and after that open next media file. But in this case the resulted video will be corrupted - some video samples from 1st file will be skipped. 

    I'm wondering - is there any way to "say" to transcoder on audio sample request (if it reached EOS) - "wait please, there is no audio data for now, ask later" like in Media Foundation?

    I've tried to delay audio sample response, but this freezes video samples requests too, looks like transcoder asking for audio, video samples in a single thread.

    Tuesday, July 1, 2014 9:22 AM

Answers

  • Hello Dmitry,

    Unfortunately I don't think your current solution is going to give you the output you are looking for. The file header may not contain the necessary information about the additional files that you are trying to append. Because of this you are going to need to find a different solution to your problem.

    It is relatively easy to implement a video editing system using the SourceReader and SinkWriter. These two components allow you to read multiple arbitrary streams and send them to a single output. You can use the SourceReader to open and trim all of your source files and you can use the SinkWriter to combine them into a single file. The SourceReady can be used to decode the files to a single uncompressed format that you can pass to the SinkWriter to compress the data. Keep in mind that you can't edit compressed video unless you are sure that the source file is chunked appropriately and that you are only appending at the beginning of chunks.

    Source Reader

    http://msdn.microsoft.com/en-us/library/windows/desktop/dd940436(v=vs.85).aspx

    Sink Writer

    http://msdn.microsoft.com/en-us/library/windows/desktop/ff819461(v=vs.85).aspx

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, July 1, 2014 11:21 PM
    Moderator

All replies

  • I'll ask our media guy to check this out.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 1, 2014 7:08 PM
    Moderator
  • Hello Dmitry,

    Unfortunately I don't think your current solution is going to give you the output you are looking for. The file header may not contain the necessary information about the additional files that you are trying to append. Because of this you are going to need to find a different solution to your problem.

    It is relatively easy to implement a video editing system using the SourceReader and SinkWriter. These two components allow you to read multiple arbitrary streams and send them to a single output. You can use the SourceReader to open and trim all of your source files and you can use the SinkWriter to combine them into a single file. The SourceReady can be used to decode the files to a single uncompressed format that you can pass to the SinkWriter to compress the data. Keep in mind that you can't edit compressed video unless you are sure that the source file is chunked appropriately and that you are only appending at the beginning of chunks.

    Source Reader

    http://msdn.microsoft.com/en-us/library/windows/desktop/dd940436(v=vs.85).aspx

    Sink Writer

    http://msdn.microsoft.com/en-us/library/windows/desktop/ff819461(v=vs.85).aspx

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, July 1, 2014 11:21 PM
    Moderator
  • Hi James,

    Thank you for your answer. To read samples i'm using IMFSourceReader, and looks like i have to replace Transcoder with IMFSinkWriter. 

    One more question - in this case how i can apply effect while reading samples with source reader and feeding it to sink writer? any suggestions?

    Wednesday, July 2, 2014 6:43 AM
  • Looks i found answer by myself, correct me if i'm wrong. Decoding\Encoding with applying effects process flow should look like this

    1. IMFSourceReader to read sample

    2. Provide sample to IMTransform via ProcessInput, get result using ProcessOutput

    3. Feed sample to IMFSinkWriter 

    Wednesday, July 2, 2014 10:12 AM
  • Hello Dmitry,

    Yes, that should work best for your video editing scenario.

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, July 2, 2014 10:08 PM
    Moderator