c++ - Encode Audio using Sink Writer -
i found this article explaing how encode video using media foundation.
i trying encode audio using principle used in above link.
i stuck on setting correct input media type sink writer.
here part:
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, mfaudioformat_float); if (succeeded(hr)) hr = pmediatypein->setuint32(mf_mt_audio_num_channels, cchannels); if (succeeded(hr)) hr = pmediatypein->setuint32(mf_mt_audio_samples_per_second, samplerate); if (succeeded(hr)) hr = psinkwriter->setinputmediatype(streamindex, pmediatypein, null);
my code fails on last line while setting input media type.
any help, how handle this?
thanks.
you need supply mf_mt_audio_bits_per_sample in media type. must set 16. check input types requirements here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd742785(v=vs.85).aspx. sample rate must either 44100 or 48000. subtype must mfaudioformat_pcm.
the important thing need call addstream on sink writer, prior calling setmediatype, output audio type enumerated call mftranscodegetaudiooutputavailabletypes function mfaudioformat_aac subtype if need encode audio aac.
mfcreatesinkwriterfromurl may not able guess need encode mp4 container m4a extension. might need supply mftranscodecontainertype_mpeg4 containe type using mf_transcode_containertype attribute when calling mfcreatesinkwriterfromurl. option use mfcreatempeg4mediasink , mfcreatesinkwriterfrommediasink instead.
Comments
Post a Comment