I've been trying to retrieve the bits per sample in the Media Foundation Framework but it always returns 0, or gives an 'requested attribute not found' HRESULT.
Here's the code I've tried, the
DWORD streamIndex = 0, flag = 0;
LONGLONG audioTimestamp = 0;
ComPtr<IMFSample> pAudioSample = nullptr;
HRESULT result = mImpl->mAudioSourceReader->ReadSample(mImpl->mAudioStreamIndex, 0, &streamIndex, &flag, &audioTimestamp, &pAudioSample);
if (result != S_OK) {
LogError("Failed to read audio sample..");
return false;
}
ComPtr<IMFMediaType> pAudioSampleMediaType;
if (S_OK != mImpl->mAudioSourceReader->GetCurrentMediaType(mImpl->mAudioStreamIndex, &pAudioSampleMediaType)) {
LogError("Failed to set resampler input...");
return false;
}
uint32_t inBitsPerSample;
result = pAudioSampleMediaType->GetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, &inBitsPerSample);
result = pAudioSample->GetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, &inBitsPerSample);
inBitsPerSample = MFGetAttributeUINT32(pAudioSample.Get(), MF_MT_AUDIO_BITS_PER_SAMPLE, 0);
The program is working, but I have set the value to 32, this presumably works because I have a 32 bit audio file. Is there something else I need to do to retrieve the bits per sample from an audio sample?
Many thanks, Peter
Edit:
Details of the media are:
Video file with LPCM Audio (mp4 container)
Sample Rate 48000 Hz
Bits Per Sample 16
Channel Count 6