Media Foundation AAC encoder trimming early samples and unable to process short files
Hi,
We're using Media Foundation to convert WAV files to AAC/MP4 in our asset importer, and we observed that the smallest size of acceptable files increased in the later versions. Previously, we were able to convert files of at least 1025 samples, but now the new minimum appears to be 2049. We identified these minimum sample counts not because of errors returned by MF, but rather because the resulting files are empty.
This was observed by comparing the 10.0.19041 to 10.0.22621. DLLs involved are likely mf.dll
, mfplat.dll
or mfAACEnc.dll
, where the latter stands out as its size went from ~140kB to ~1.5MB.
To convert these files we do the following:
- Create a media source with
MFCreateSourceResolver
- Create an output profile with
MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION
to0x29
andMFTranscodeContainerType_MPEG4
as container - Create a topology based on these source and profile
- Run this topology on a media session and wait for the MESessionClosed event
- We also noticed that the beginning of AAC tracks always "fade in" during the first ~1000 samples, which doesn't happen when doing the same conversions with ffmpeg, avconv or afconvert. This appears to be because of the priming of the encoder, but can likely be fixed by prepending some silence to the file and offsetting the start of the file in the MP4 container using
edts
/elst
but we weren't able to identify how to do that with MF.
Is there a workaround for this, or would there be another way to encode short files?
Thank you!