API在Android解码AAC

API在Android解码AAC

本文介绍了使用媒体codeC API在Android解码AAC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的媒体codeC API在Android上脱code的AAC流。 (这是原始的AAC)。我试着用MediaFormat.createAudioFormat()创建格式对象传递给媒体codec.configure(),但我一直使用的AAC(音频/ MP4A-LATM)时遇到错误。 (它与MP3(音频/ MPEG),虽然...)

I'm trying to used the MediaCodec API on Android to decode an AAC stream. (It's raw AAC.) I tried using the MediaFormat.createAudioFormat() to create the format object to pass to MediaCodec.configure(), but I kept getting errors when using AAC (audio/mp4a-latm). (It works with MP3 (audio/mpeg) though...)

最后,我创建了一个MediaExtractor为AAC文件,并看了看格式对象它被生产。我看到它列入重点CSD-0为ByteBuffer的两个字节都与值×12组成。如果我包括键和值格式的对象,我用配置AAC codeC,一切正常。

Finally I created a MediaExtractor for an AAC file and looked at the format object it was producing. I saw that it included the key "csd-0" for a ByteBuffer composed of two bytes both with the value 0x12. If I include that key and value in the format object that I used to configure the AAC codec, everything works.

有没有人有一个想法是怎么回事?该文件指出,我不应该配置的重点。有没有人有一个指向媒体codeC的例子脱code AAC文件,而无需使用MediaExtractor生成格式对象?

Does anyone have an idea what is going on? The documentation states that I shouldn't configure that key. Does anyone have a pointer to MediaCodec examples to decode AAC files without using MediaExtractor to generate the format object?

推荐答案

是的,codeC配置2个字节是收到的首字母。是的是的原始AAC数据块。你可以看到我是如何获得,而下面的编码格式。我最初试图按照文档,里面说他们是在LATM格式,并试图解析。然后,我发现了一些在Android文档提到的输出确实是原始块'差异'。明知那么,它是简单地选择一个容器,我需要的问题。特别是,我需要的ADTS容器,而不是FLV或MP4。

Yes, the codec config 2 bytes are the initial you receive. And yes it is raw aac data blocks. You can see how I derive the format below while encoding. I initially tried to follow the documentation, which said they are in latm format, and tried to parse that. I then found some 'diff' on the android documentation that said the output was indeed raw blocks. Knowing that then, it was simply a matter of choosing a container for my needs. In particular, I needed the adts container rather than flv or mp4.

复制的有效载荷数据到一个数组,它是为你的容器足够大,只需添加上你的位。所以冲刷互联网为我的解决方案后,我产生了以下code:

Copying the payload data into an array that is large enough for your container, just add on your bits. So after scouring the internet for my solution I produced the following code:

profile = (configParams[0]>>3)&0x1f;

frequency_index = (this.configParams[0]&0x7) <<1 | (this.configParams[1]>>7) &0x1;

channel_config = (this.configParams[1]>>3) &0xf;

int finallength = encoded_length + 7;
ENCodedByteArray[0] = (byte) 0xff;
ENCodedByteArray[1] = (byte) 0xf1;
ENCodedByteArray[2] = (byte) ( ((profile - 1) << 6) + (frequency_index << 2) +(channel_config >> 2));
ENCodedByteArray[3] = (byte) (((channel_config & 0x3) << 6) + (finallength >> 11));
ENCodedByteArray[4] = (byte)( (finallength & 0x7ff) >> 3);
ENCodedByteArray[5] = (byte) (((finallength & 7) << 5) + 0x1f) ;
ENCodedByteArray[6] = (byte) 0xfc;

使用这样的:

Using something like this:

byte chunkADTS[]=new byte[info.size + 7];
fillInADTSHeader(chunkADTS,info.size);
outputBuffers[bR].get(chunkADTS,7,info.size);
buffer.pushData(chunkADTS);

这篇关于使用媒体codeC API在Android解码AAC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 18:32