locked
Audio is incorrect while using sinkwriter

    Question

  • I set the following parameters for mp4(H264+AAC) encoding using sinkwriter. but the output file's audio is incorrect. Can you tell me how to set the parameter? BTW, the WMA's parameter also is a problem, can you give me a good sample for setting such parameters?

     

    MFCreateMediaType(&pOutAudioType);

    pOutAudioType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);

    pOutAudioType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_AAC);

    pOutAudioType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 48000);

    pOutAudioType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 12000);

    pOutAudioType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS,2);

    pOutAudioType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16);

    pOutAudioType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, 1);

    pOutAudioType->SetUINT32(MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1);

    pOutAudioType->SetUINT32(MF_MT_COMPRESSED, 1);

    pOutAudioType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, 1);

    hr = m_pSinkWriter->AddStream(pOutAudioType.Get(), &m_dwAudioStreamIndex);

    hr = MFCreateMediaType(&pInAudioType);      

    hr = pInAudioType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio); 

    hr = pInAudioType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM); 

    hr = pInAudioType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16);

    hr = pInAudioType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 48000);

    hr = pInAudioType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS,2);  

    hr = pInAudioType->SetUINT32( MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1 );

    hr = pInAudioType->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, 16 / 8 * 2);

    hr = pInAudioType->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 16/ 8 * 2* 48000);

    hr = m_pSinkWriter->SetInputMediaType(m_dwAudioStreamIndex, pInAudioType.Get(), NULL);


    Friday, September 7, 2012 2:54 AM

Answers

  • I have fixed it ,because I have reused the IMFSample but the IMFSinkWriter seem buffer the sample. :)
    • Marked as answer by Tony_Jennifer Monday, October 29, 2012 2:43 AM
    Monday, October 29, 2012 2:43 AM

All replies

  • Hello,

    Are you sure that your input media type actually matches the media type of the data that you are sending to the sink writer? It is extremely likely that you have a mismatch be tween the format that you are setting up and the actual format of the data that you are sending.

    I hope this helps,

    James


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

    Friday, September 7, 2012 8:51 PM
    Moderator
  • I am sure that the PCM is 48000/16bit/2 channel, because I can play the audio correctly. it is wrong for transcoding, the output audio is choppy

    Monday, September 10, 2012 1:54 AM
  • You should not hear any audio artifacts in the transcoded file if you are using the Sink Writer properly. It could be a timestamp issue. Please verify that you are producing time stamps for your samples correctly. If you feel that you are doing everything correctly you can provide a small sample application that reproduces the issue along with the sample output file. Please put these samples on your Skydrive and provide a link here. I will grab the files and see if I can figure out what is going wrong.

    -James


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

    Monday, September 17, 2012 9:17 PM
    Moderator
  • Hi James,

         Thank you very much , I have put the sample app,result file and sample encode for configure parameters into one zip file, you can get it from https://skydrive.live.com/redir?resid=12C36C4AA8E715AD!411&authkey=!AKVtEbQVmRX1UgU ,Please help me debug it. To use this sample app, you just need do the following:

    1)Open a file  2) click transcode button, then you can select the saving file. BTW, you can test the preview. the data for preview is same as the data for transcoding

    Thank you again

    Thursday, October 18, 2012 8:08 AM
  • I have fixed it ,because I have reused the IMFSample but the IMFSinkWriter seem buffer the sample. :)
    • Marked as answer by Tony_Jennifer Monday, October 29, 2012 2:43 AM
    Monday, October 29, 2012 2:43 AM