gpt4 book ai didi

Android MediaCodec 不解码所有输入缓冲区

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:59 26 4
gpt4 key购买 nike

在 Android 4.4.2 中,我使用 MediaCodec 解码 mp3 文件。我正在使用 queueInputBuffer() 对输入的 mp3 编码帧进行排队,并使用 dequeueOutputBuffer() 获取解码帧。但是解码器从第 8 帧开始提供解码输出(基于 bufferInfo.presentationTimeUs)并跳过最初的 7 帧。这种情况只发生在少数流中,而不是所有流中。此外,这种行为在多次运行中都是一致的。

我想要所有帧的解码输出,我不想跳过任何帧。谁能帮我理解为什么跳过帧?我保证流没有损坏。因为我得到 INFO_TRY_AGAIN 直到第 7 帧,当 `dequeueOutputBuffer' 返回有效的缓冲区索引时,它的显示时间总是第 8 帧。

排队代码如下:

Log.e(TAG, "audptOffset = "+audptOffset+"input PT = "+audpt);
audcodec.queueInputBuffer(audInbufIndex, 0, audchunkSize, audpt, 0);

以下是我调用 dequeue 并写入 AudioTrack 的方式:

if(!audoutputDone ){
if(!waitForAudioRelease){
auoutBufIndex = audcodec.dequeueOutputBuffer(auinfo, 100);
Log.e(TAG, "Output PT = " + auinfo.presentationTimeUs+"auoutBufIndex = "+auoutBufIndex);
}
if (auoutBufIndex >= 0) {
waitForAudioRelease = true;
} else if (auoutBufIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
auddecOutBufArray = audcodec.getOutputBuffers();
} else if (auoutBufIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
MediaFormat newFormat = audcodec.getOutputFormat();
int sampleRate1 = newFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int channelCount1 =newFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
Log.e(TAG, "INFO_OUTPUT_FORMAT_CHANGED");
int minBufSize1 = AudioTrack.getMinBufferSize(sampleRate1, (channelCount1==2)?
AudioFormat.CHANNEL_OUT_STEREO:AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
sampleRate1, (channelCount1==2)?AudioFormat.CHANNEL_OUT_STEREO:AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, minBufSize1,
AudioTrack.MODE_STREAM);
audioTrack.play();
waitForAudioRelease = false;
}
audionowUs = System.currentTimeMillis();
if (auoutBufIndex >= 0) {
auwhenRealUs = (auinfo.presentationTimeUs/1000) + mStartTimeRealMs - (audptOffset/1000);
aulateByUs = audionowUs - auwhenRealUs;


if(!audioWaitTillStartTime){
while((mStartTimeRealMs+((auinfo.presentationTimeUs/1000) - (audptOffset/1000))) >= audionowUs){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
audionowUs = System.currentTimeMillis();
}
Log.e(TAG,"Play is going to start PT Difference = "+((auinfo.presentationTimeUs/1000) - (audptOffset/1000)));
}

添加更多日志:

02-22 17:46:03.164: E/CL(28650): received play command from server
02-22 17:46:03.209: E/RealTimeClient(28650): created decoder for audio/mpeg
02-22 17:46:03.234: E/Music(28650): Output PT = 0
02-22 17:46:03.234: E/Music(28650): pt of first frame received 1215000
02-22 17:46:03.234: E/Music(28650): Input PT = 1215000
02-22 17:46:03.234: E/Music(28650): Output PT = 0
02-22 17:46:03.234: E/Music(28650): Input PT = 1241122
02-22 17:46:03.239: E/Music(28650): Output PT = 0
02-22 17:46:03.239: E/Music(28650): Input PT = 1267244
02-22 17:46:03.239: E/Music(28650): Output PT = 0
02-22 17:46:03.239: E/Music(28650): Input PT = 1293367
02-22 17:46:03.239: E/Music(28650): Output PT = 0
02-22 17:46:03.239: E/Music(28650): Input PT = 1319489
02-22 17:46:03.239: E/Music(28650): Output PT = 0
02-22 17:46:03.244: E/Music(28650): INFO_OUTPUT_FORMAT_CHANGED
02-22 17:46:03.249: I/Reverb(28650): getpid() 28650, IPCThreadState::self()->getCallingPid() 28650
02-22 17:46:03.249: E/Reverb(28650): Reverb::StartElementHandler, wrong element or attributes: boolean
02-22 17:46:03.249: E/Music(28650): Input PT = 1345612
02-22 17:46:03.254: E/Music(28650): Output PT = 1293367
02-22 17:46:03.259: E/Music(28650): Input PT = 1371734
02-22 17:46:03.259: E/Music(28650): Input PT = 1397857
02-22 17:46:03.259: E/Music(28650): Input PT = 1423979
02-22 17:46:03.259: E/Music(28650): Input PT = 1450102
02-22 17:46:03.264: E/Music(28650): Input PT = 1476224
02-22 17:46:03.269: E/Music(28650): Input PT = 1502346
02-22 17:46:03.269: E/Music(28650): Input PT = 1528469
02-22 17:46:03.269: E/Music(28650): Input PT = 1554591
02-22 17:46:03.269: E/Music(28650): Input PT = 1580714
02-22 17:46:03.269: E/Music(28650): Input PT = 1606836
02-22 17:46:03.269: E/Music(28650): Input PT = 1632959
02-22 17:46:03.269: E/Music(28650): Input PT = 1659081
02-22 17:46:04.124: W/AudioTrack(28650): releaseBuffer() track 0x5e2faf28 name=0x3 disabled, restarting
02-22 17:46:04.129: E/Music(28650): Output PT = 1319489
02-22 17:46:04.129: E/Music(28650): Input PT = 1685204
02-22 17:46:04.159: E/Music(28650): Output PT = 1345612

最佳答案

MPEG-1 Layer III (MP3) 具有依赖帧,您不能只从任何帧开始,例如 Layer I 或 Layer II。引用自提供的 link ,“在最坏的情况下,可能需要 9 个输入帧才能解码一帧。”这很可能就是您所看到的。尽管前 7 帧中的每一帧都有与之关联的 PTS,但直到您到达第 8 帧时,解码器才真正能够完全解码帧并开始播放。回放从第 8 帧 PTS 开始。您将需要痛苦地手动解析有问题的流的字节以完全验证正在发生的事情,但我怀疑您实际上正在播放所有帧。

关于Android MediaCodec 不解码所有输入缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34990131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com