简体   繁体   English

使用mediacodec的Aac编码器用一个通道初始化,但输出为两个通道

[英]Aac encoder using mediacodec was initialized with one channel but outputs as two channels

The aac decoder is initialized as below: AAC解码器初始化如下:

MediaFormat outfmt = new MediaFormat();
outfmt.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
outfmt.setInteger(MediaFormat.KEY_AAC_PROFILE, mAudioProfile);
mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
outfmt.setInteger(MediaFormat.KEY_SAMPLE_RATE, mSampleRate);
mChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
outfmt.setInteger(MediaFormat.KEY_CHANNEL_COUNT, mChannels);
outfmt.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
audioEncoder.configure(outfmt, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
            audioEncoder.start();

But the encoder behaviors different on two devices. 但是编码器在两个设备上的行为不同。

One outputs normal presentation: 64000 128000 192000 256000 320000 一个输出正常显示:64000 128000 192000 256000 320000

Another outputs as two channels: 64000 64000 128000 128000 192000 192000 256000 256000 320000 320000 另一个输出为两个通道:64000 64000 128000 128000 192000 192000 256000 256000 320000 320000

And the format extracted using MediaExtractor is different on two devices: 使用MediaExtractor提取的格式在两个设备上是不同的:

the normal one is {max-input-size=1572864, aac-profile=2, csd-0=java.nio.ByteArrayBuffer[position=0,limit=2,capacity=2], sample-rate=16000, durationUs=8640000, channel-count=1, mime=audio/mp4a-latm, isDMCMMExtractor=1} 正常的是{max-input-size = 1572864,aac-profile = 2,csd-0 = java.nio.ByteArrayBuffer [position = 0,limit = 2,capacity = 2],sample-rate = 16000,durationUs = 8640000,频道计数= 1,mime =音频/ mp4a-latm,isDMCMMExtractor = 1}

The other is {max-input-size=798, durationUs=8640000, channel-count=1, mime=audio/mp4a-latm, csd-0=java.nio.ByteArrayBuffer[position=0,limit=2,capacity=2], sample-rate=16000} 另一个是{max-input-size = 798,durationUs = 8640000,channel-count = 1,mime = audio / mp4a-latm,csd-0 = java.nio.ByteArrayBuffer [position = 0,limit = 2,capacity = 2],采样率= 16000}

So the original audio has one channel and the encoder is configured with one channel too.But the encoder outputs as in two channel way. 因此原始音频只有一个通道,编码器也配置有一个通道,但是编码器以两通道方式输出。

Does it matter with isDMCMMExtractor flag? 与isDMCMMExtractor标志有关系吗?

Help!Help! 救命!救命! @fadden @fadden

First off, the question is very hard to understand - both of the listed MediaFormat contents show channel-count=1 , so there's very little actual explanation of the issue itself, only an explanation of other surrounding details. 首先,这个问题很难理解-列出的两个MediaFormat内容都显示channel-count=1 ,因此对该问题本身的实际解释很少,而仅是其他周围细节的解释。

However - the software AAC decoder in some android versions (4.1 if I remember correctly, possibly 4.2 as well) will decode mono AAC into stereo - not sure if some of the hardware AAC decoders do the same. 但是-一些Android版本的软件AAC解码器(如果我没记错的话是4.1,也许还有4.2)会将单声道AAC解码为立体声-不确定某些硬件AAC解码器是否也这样做。 You can argue whether this is a bug or just unexpected behaviour, but it's something you have to live with. 您可以争论这是错误还是只是意外行为,但这是您必须忍受的。 In the case that the decoder returns stereo data even though the input was mono, both stereo channels will have the same (mono) content. 如果即使输入是单声道,解码器仍返回立体声数据,则两个立体声通道将具有相同的(单声道)内容。

So basically, you have to be prepared to handle this - either pass the actual format information from the decoder (not from MediaExtractor) to whoever is using the data (eg reconfigure the audio output to stereo), or be prepared to mix down stereo back into mono if you really need to have the output in mono format. 因此,基本上,您必须准备好进行处理-将实际的格式信息从解码器(而不是从MediaExtractor)传递给正在使用数据的任何人(例如,将音频输出重新配置为立体声),或者准备将立体声混音回传如果您确实需要采用Mono格式的输出,则将其转换为Mono。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM