locked
What kind of Stream to feed into MediaTranscoder::PrepareStreamTranscodeAsync?

    Question

  • InMemoryRandomAccessStreams are for some weird reason not allowed. So how are we suppose to use the method?
    Friday, July 11, 2014 11:40 PM

All replies

  • Hi,

    Please refer to the link:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.media.transcoding.mediatranscoder.preparestreamtranscodeasync.aspx

    source

    Type: IRandomAccessStream

    The source stream.

    source must be a  IRandomAccessStream and cannot be a InMemoryRandomAccessStream  or other runtime classes which implements IRandomAccessStream.

    destination

    Type: IRandomAccessStream

    The destination stream.

    destination must be a  IRandomAccessStream and cannot be a InMemoryRandomAccessStream  or other runtime classes which implements IRandomAccessStream.

    And you can refer to the Transcoding media sample

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, July 14, 2014 5:13 AM
  • Anne, did you read my question? I read the Docs, and they (as you also quoted) state clearly that "and cannot be a InMemoryRandomAccessStream".

    So, WHAT kind of arguments should I pass in? What other objects implement IRandomAccessStream?!

    Monday, July 14, 2014 8:35 AM
  • Hi,

    You can see my first reply:

    I already say the parameter  must be a  IRandomAccessStream.

    And other than InMemoryRandomAccessStream ,FileRandomAccessStreamRandomAccessStreamOverStream also implement IRandomAccessStream.

    You can see Windows.Storage.Streams namespace

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.


    Monday, July 14, 2014 9:16 AM
  • I know that already. Its in the docs. What objects in WinRT implement this interface? And for what crazy reason it cannot be n InMemoryRandomAccessStream?
    Monday, July 14, 2014 9:33 AM
  • Hi,

    Would you see my reply:

    And other than InMemoryRandomAccessStream ,FileRandomAccessStreamRandomAccessStreamOverStream also implement IRandomAccessStream.

    All of class which implement IRandomAccessStream cannot used. You should define IRandomAccessStream  and  use it.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.


    Monday, July 14, 2014 9:38 AM
  • I already tried RandomAccessStreamOverStream without luck. I do get an "Unknown" conversion error.

    I think at that point, I might very well just convert the raw data by hand. Should be done in less than a day that it took me already how to use this API.

    Thanks for you help though.

    Please ask the Product team, why the use of InMemoryRandomAccessStream is forbidden.

    Monday, July 14, 2014 9:48 AM
  • Hi,

    May be you misunderstand my reply. All of class which implement IRandomAccessStream cannot used in MediaTranscoder::PrepareStreamTranscodeAsync method. No matter  InMemoryRandomAccessStream ,FileRandomAccessStream or RandomAccessStreamOverStream.

    You should define two IRandomAccessStream type and then used them in PrepareStreamTranscodeAsync method:

    IRandomAccessStream ^streamsource;
    IRandomAccessStream ^streamdestination;

    I create a project which can use the PrepareStreamTranscodeAsync method:

    // // MainPage.xaml.cpp // Implementation of the MainPage class. // #include "pch.h" #include "MainPage.xaml.h" using namespace Transcoding__; using namespace Platform; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Xaml::Controls::Primitives; using namespace Windows::UI::Xaml::Data; using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; using namespace Windows::Storage::Streams; using namespace Windows::Storage::Pickers; using namespace concurrency; using namespace Windows::Storage; using namespace Windows::Storage::Streams; using namespace Windows::Media::Transcoding; using namespace Windows::Media::MediaProperties; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 StorageFile ^source; StorageFile ^destination; IRandomAccessStream ^streamsource; IRandomAccessStream ^streamdestination; MainPage::MainPage() { InitializeComponent(); TranscodeVideoFile(); } void MainPage::TranscodeVideoFile() { FileOpenPicker^ picker = ref new FileOpenPicker(); picker->SuggestedStartLocation = PickerLocationId::VideosLibrary; picker->FileTypeFilter->Append(".wmv"); picker->FileTypeFilter->Append(".mp4"); FileSavePicker^ savepicker = ref new FileSavePicker(); savepicker->SuggestedStartLocation = PickerLocationId::VideosLibrary; auto plainTextExtensions = ref new Platform::Collections::Vector<String^>(); plainTextExtensions->Append(".mp4"); savepicker->FileTypeChoices->Insert("MPEG4", plainTextExtensions); savepicker->SuggestedFileName = "New Video"; savepicker->DefaultFileExtension = ".mp4"; create_task(picker->PickSingleFileAsync()).then( [this](StorageFile^ inputFile) { try { source = inputFile; if (source != nullptr) { return inputFile->OpenAsync(FileAccessMode::ReadWrite); } } catch (Platform::Exception^ exception) { } }).then( [this,savepicker](IRandomAccessStream^ inputStream) { try { streamsource = inputStream; return savepicker->PickSaveFileAsync(); } catch (Platform::Exception^ exception) { } }).then( [this](StorageFile^ outputFile) { try { destination = outputFile; if (destination != nullptr) { return outputFile->OpenAsync(FileAccessMode::ReadWrite); } } catch (Platform::Exception^ exception) { } }).then( [this](IRandomAccessStream^ outputStream) { try { streamdestination = outputStream; } catch (Platform::Exception^ exception) { } }); TranscodeFile(streamsource, streamdestination); }

    //transcode file by this method void MainPage::TranscodeFile(IRandomAccessStream ^sourcestream, IRandomAccessStream^destinationstream) { MediaEncodingProfile ^profile = MediaEncodingProfile::CreateMp4(VideoEncodingQuality::HD720p); MediaTranscoder ^transcoder = ref new MediaTranscoder(); create_task(transcoder->PrepareStreamTranscodeAsync(sourcestream, destinationstream, profile)).then([this](PrepareTranscodeResult ^prepareOp) { try { if (prepareOp->CanTranscode) { auto transcodeOp = prepareOp->TranscodeAsync(); } } catch (Platform::Exception^ exception) { } }); }

    I think this is by design that  InMemoryRandomAccessStream cannot used in this method.

    And I suggest you can use MediaTranscoder.PrepareFileTranscodeAsyncto transcode, Which parameter is the type of storageFile. If you have some InMemoryRandomAccessStream data, you can save the stream into storageFile and then use the MediaTranscoder.PrepareFileTranscodeAsyncto transcode. Please refer to the link below to get more information about how to write InMemoryRandomAccessStream to file: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/85425fc4-1b75-4ec4-a621-634d51261f0b/how-to-write-inmemoryrandomaccessstream-to-file?forum=winappswithcsharp

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.



    Tuesday, July 15, 2014 8:06 AM
  • This makes no sense, Anne, unfortunately. There is a prepareFileTranscode for files and one for streams. To use file streams in the one for streams is not helping me at all, cause I do not have files to begin with. I have one source that implements IRandomAccessStream and want to transcode that in memory.

    How hard can it be do design the API to work in that case? Why provide a prepareStreamTranscode method if its only usable with streams coming from IStorageFile?

    Can you get in touch with the Product owner of this API to get this cleared up? Its confusing as hell!

    Thanks!

    Tuesday, July 15, 2014 8:30 AM
  • Hi,

    Do you see the codes in my reply. I create two IRandomAccessStream type parameter which can used in the PrepareStreamTranscodeAsync method. And the souce which you implements IRandomAccessStream you can save the source to a storage file and then use  MediaTranscoder.PrepareFileTranscodeAsync to transcode the saved file.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.




    Tuesday, July 15, 2014 8:36 AM
  • Hi,

    And thanks for your suggestion. I will help you to submit a custom wish to product team.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Tuesday, July 15, 2014 9:07 AM
  • I see your code and see that you use a filepicker to let the user pick the soruce and destination file. You could then just use the prepareFileTranscode with the picked files and could skip the part of getting the streams to the files. In my scenario, there are no files, no pickers nothing. User interaction is not required. Files are not used.

    I have a stream from the SpeechSythesizer that I want to transcode. That stream lives in memory, not in a file. I want to transcode it in-memory, never write it to a file. This scenario should be supported by the transcodeToStream method. 

    Oh and while you are in contact with the product team: "Unknown" is a useless error. Be more descriptive!

    Tuesday, July 15, 2014 9:17 AM
  • Hello Anne,

    I think we should not mark this thread as answered yet. That might be misleading to readers that look for a real answer. And the initial issue is not solved yet.

    We cannot call the PrepareStreamTranscodeAsync API without resorting to file streams in some way or another.

    Thursday, July 24, 2014 8:12 AM