0

I have been able to use sink write to read rgb32 data in a file to generate an mp4 video, please refer to the example on the official website https://learn.microsoft.com/zh-cn/windows/win32/medfound/tutorial--using-the-sink-writer-to-encode-video Now,I wanted a similar idea to write a pcm generated data to an aac or mp3 file, but there were some problems with the code:


HRESULT InitializeSinkWriter(IMFSinkWriter** ppWriter, DWORD* pStreamIndex)
{
    HRESULT hr = S_OK;
    *ppWriter = NULL;
    *pStreamIndex = NULL;

    DWORD streamIndex;
    IMFSinkWriter* pSinkWriter = NULL;
    IMFMediaType* pMediaTypeOut = NULL;
    IMFMediaType* pMediaTypeIn = NULL;


    // Set the input media type.
    if (SUCCEEDED(hr))
    {
        hr = MFCreateMediaType(&pMediaTypeIn);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, _recorderConf.audioInPutFormat);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, _recorderConf.audioChannelNum);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, _recorderConf.audioSamplePerSec);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, _recorderConf.audioBitPerSample);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, _recorderConf.audioBytesPerSecond);
    }
    if (SUCCEEDED(hr))
    {
        hr = pMediaTypeIn->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, _recorderConf.audioSampleIndependent);
    }
    if (SUCCEEDED(hr))
    {
        hr = pSinkWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL);
    }

}

hr = pSinkWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL); The hr return value for this line is: 0xc00d36b4 : The data specified for the media type is invalid, inconsistent, or not supported by this object。 I want to know what went wrong and what is the right way to do it

I want to know what went wrong and what is the right way to do it

dyang
  • 1

0 Answers0