问题
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