MediaCodec - strange error when sending EOS buffer into audio decoder

帅比萌擦擦* 提交于 2020-03-19 07:49:58

问题


I'm working on replacing the audio track of my video with music from another file. So I modified the standard ExtractDecodeEditEncodeTest code (from bigflake) so that the audio MediaExtractor is created from said 'another file'. A strange thing happens when I try to send an EOS buffer into the audio decoder, however, in this line:

this.audioDecoder.queueInputBuffer(decoderInputBufferIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);

This netted me an android.media.MediaCodec$CodecException: Error 0xfffffff3.

When I caught it in a try-catch-finally loop, it's apparently an android.media.MediaCodec.error_neg_13 (code: -13). The video still came out seemingly fine, however, with the replaced audio track.

As far as I searched, there is nothing about this error ,not even in the logs. Does anyone know what causes it and how I can prevent it from happening?


回答1:


You get the android.media.MediaCodec.error_neg_13 if the MediaCodec.BUFFER_FLAG_END_OF_STREAM is sent in a buffer that contains data to be processed instead of in an empty buffer.

My solution was to send the MediaCodec.BUFFER_FLAG_END_OF_STREAM in a separate buffer not containing any data.

During my research of this error i did not find any reference to the android.media.MediaCodec.error_neg_13, not even in the libstagefright source code so i'm not sure if this is the only cause.




回答2:


I managed to avoid the error by sending the EOS flag into the Encoder only after checking the presentationTimeUs in the decoder output buffer info, instead of doing it when queueing the decoder's input buffer.

The code:

if(presentationTime < totalTime) {                            
    audioEncoder.queueInputBuffer(encoderInputBufferIndex, 0, size, presentationTime, audioDecoderOutputBufferInfo.flags);
} else {
    audioEncoder.queueInputBuffer(encoderInputBufferIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM); }

That code is executed after processing the audio buffer, and presentationTime and size are changed from the original audioDecoderOutputBufferInfo. Basically, between getting the decoder's output buffer and sending the data into the encoder's input buffer - not before sending the extracted data/sample into the decoder's input buffer.

NOTE: Let me know if the full portion of the code is needed.



来源:https://stackoverflow.com/questions/48919712/mediacodec-strange-error-when-sending-eos-buffer-into-audio-decoder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!