locked
set a video/audio encoder's parameter

    Question

  • Hi,
        I am using media foundation (sinkwriter) to write a video encoding program of metro style, but i don't know what parameters i can set about the codec. i can use

    MFTranscodeGetAudioOutputAvailableTypes to enum the types i can set, but it can't be used in metro. is there any interface i can use to enum the parameters about some codec like this function?

    Thanks.


     
    Thursday, April 12, 2012 6:56 AM

All replies

  • Hello,

     

    Thanks for your feedback, I will involve more experts to investigate it.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, April 13, 2012 8:22 AM
  • Hello Hans,

    Your exact problem is not clear to me. How are you setting up your IMFSinkWriter interface? You should be able to configure your stream settings via the IMFMediaType that you are passing to "AddStream". Remember that I MFMediaType inherits from IMFAttributes.

    Does this answer your question?

    Thanks,

    James 


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

    Tuesday, April 17, 2012 12:21 AM
    Moderator
  • HI James,

    Thank you for your replies.

    My question is how to configure the IMFMediaType or how can i  enumerate the output types that encoder supported in matro style app?

    i have code that configure wmaudiov9 encoder, when i set MF_MT_AUDIO_AVG_BYTES_PER_SECOND == 32001, everything is okay, but when i change it to other values, such as 32000, pSinkWriter- >SetInputMediaType will fail. So i want to enumerate the output types in my app so that i can select  the one that matches my requirements, but the functions  MFTEnum and MFTEnumEx are not support in metro. 

    So i want to know is there any method that i can get all of the parameters the encoder supported?

    Here is my sample code:

    CHECK_HR( MFCreateMediaType( &spMFTypeOut ) );
        CHECK_HR( spMFTypeOut->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio ) );  
        CHECK_HR( spMFTypeOut->SetGUID( MF_MT_SUBTYPE, MFAudioFormat_WMAudioV9 ) );
        CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, SAMPLES_PER_SECOND ) );
        //CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 32001  ) );  // MF_MT_AUDIO_AVG_BYTES_PER_SECOND == 32001 is okay, but when i change it to other value, such as 32000, pSinkWriter- >SetInputMediaType will fail. 

        CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, NUM_CHANNELS ) );
        CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, BITS_PER_SAMPLE ) );
        CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1 ) );
        CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_ALL_SAMPLES_INDEPENDENT, 1 ) );
        CHECK_HR( spMFTypeOut->SetUINT32( MF_MT_FIXED_SIZE_SAMPLES, 1 ) );

        CHECK_HR( hr = pSinkWriter->AddStream( (IMFMediaType*)spMFTypeOut, &sindex ) );

        CHECK_HR( MFCreateMediaType( &spMFTypeIn ) );
        CHECK_HR( spMFTypeIn->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio ) );
        CHECK_HR( spMFTypeIn->SetGUID( MF_MT_SUBTYPE, MFAudioFormat_PCM ) );  
        CHECK_HR( spMFTypeIn->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, BITS_PER_SAMPLE ) );
        CHECK_HR( spMFTypeIn->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, SAMPLES_PER_SECOND ) );
        CHECK_HR( spMFTypeIn->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, NUM_CHANNELS ) );
        CHECK_HR( spMFTypeIn->SetUINT32( MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1 ) );
        CHECK_HR( spMFTypeIn->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, BITS_PER_SAMPLE / 8 * NUM_CHANNELS ) );
        CHECK_HR( spMFTypeIn->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, BITS_PER_SAMPLE / 8 * NUM_CHANNELS * SAMPLES_PER_SECOND ) );
        

    ( hr = pSinkWriter->SetInputMediaType( sindex, spMFTypeIn, NULL ) );



    • Edited by Hans567 Tuesday, April 17, 2012 7:21 AM
    Tuesday, April 17, 2012 7:16 AM
  • Hello Hans,

    Thank you very much for your clarification. Unfortunately I don't believe that the scenario that you describe can be solved by using either MFTEnum or MFTEnumEx. These two APIs only return the major type and / or sub type for various MFTs that are available on the system. AFAIK they don't return specific predefined codec profiles. To understand the exact settings that a particular codec will accept you really need to understand the way the codec works. In this case your "average bytes per second" calculation must be based on your "samples per second" setting. So in this case you just need to make sure your math is correct. You might want to take a look at the WAVEFORMATEX structure to get a better fell for what is expected.

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

    Does this help?

    James


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

    Wednesday, April 18, 2012 12:56 AM
    Moderator