I used the Android MediaCodec library to transcode video files (basically, change )
Another thing I want to achieve is to truncate the video - only start 15 seconds. The logic is to check videoExtractor.getSampleTime() , if it is more than 15 seconds, I just write EOS to the decoder buffer.
But I get an exception Caused by: android.media.MediaCodec$CodecException: Error 0xfffffff3
Here is my code:
while ((!videoEncoderDone) || (!audioEncoderDone)) { while (!videoExtractorDone && (encoderOutputVideoFormat == null || muxing)) { int decoderInputBufferIndex = videoDecoder.dequeueInputBuffer(TIMEOUT_USEC); if (decoderInputBufferIndex == MediaCodec.INFO_TRY_AGAIN_LATER) break; ByteBuffer decoderInputBuffer = videoDecoderInputBuffers[decoderInputBufferIndex]; int size = videoExtractor.readSampleData(decoderInputBuffer, 0); long presentationTime = videoExtractor.getSampleTime(); if (size >= 0) { videoDecoder.queueInputBuffer( decoderInputBufferIndex, 0, size, presentationTime, videoExtractor.getSampleFlags()); } videoExtractorDone = !videoExtractor.advance(); if (!videoExtractorDone && videoExtractor.getSampleTime() > mVideoDurationLimit * 1000000) { videoExtractorDone = true; } if (videoExtractorDone) videoDecoder.queueInputBuffer(decoderInputBufferIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM); break; }
Full source code can be found here .
android mediacodec
Qylin
source share