0

Android MediaExtractor not removing ADTS headers from AAC stream.

I have AAC LC files with ADTS header and using MediaExtractor to get the audio frames. These frames are then fed to MediaMuxer to generate mp4 file. This mp4 also contains H264.

I observe that MediaExtractor removes ADTS header when reading the samples. But in one of the devices it is not removing the headers and muxer includes the header in mp4 file. This is making the final mp4 not playable on default players.

val mediaExtractor = MediaExtractor()
mediaExtractor.setDataSource(filePath)
mediaExtractor.selectTrack(0)
val chunkSize = mediaExtractor.readSampleData(inputBuffer, 0)

Here chunkSize will be equal to AAC frame length in faulty device and in others it is (AAC frame length - AAC header length).

This is the format obtained from MediaExtractor :

{sample-rate=32000, track-id=1, file-format=audio/aac, durationUs=60256000, aac-format-adif=0, is-adts=1, mime=audio/mp4a-latm, channel-count=1, language=, aac-profile=2, max-input-size=262144, csd-0=java.nio.HeapByteBuffer[pos=0 lim=2 cap=2]}

This matches with the format obtained on other devices. How can I force the extractor to remove the headers? Or can muxer handle this?

0 Answers0