Когда я использую медиа-код c аудио, сливающийся с видео, я просто хочу захватить аудио фрагмент из 10 секунд аудио, когда я вызываю android. СМИ. MediaExtractor # seekTo, введенный в 10 с параметрами, при окончательной остановке MediaMuxer будет ошибка, пример кода:
private void startAudioCodec(MediaCodec decoder, MediaCodec encoder, MediaExtractor extractor, long firstSampleTime, long startPosition, long duration) {
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
MediaCodec.BufferInfo outputInfo = new MediaCodec.BufferInfo();
boolean done = false;
boolean inputDone = false;
boolean decodeDone = false;
extractor.seekTo(firstSampleTime + startPosition, SEEK_TO_PREVIOUS_SYNC);
int decodeinput = 0;
int encodeinput = 0;
int encodeoutput = 0;
long lastEncodeOutputTimeStamp = -1;
int channelCount = 1;
info.presentationTimeUs = 0;
while (!done) {
if (!inputDone) {
int inputIndex = decoder.dequeueInputBuffer(TIMEOUT_USEC);
if (inputIndex >= 0) {
ByteBuffer inputBuffer = decoder.getInputBuffer(inputIndex);
inputBuffer.clear();
int readSampleData = extractor.readSampleData(inputBuffer, 0);
long dur = extractor.getSampleTime() - firstSampleTime - startPosition;
if ((dur < duration) && readSampleData > 0) {
decoder.queueInputBuffer(inputIndex, 0, readSampleData, extractor.getSampleTime()-startPosition, 0);//pts need to subtract the value of startPosition
decodeinput++;
// System.out.println("videoCliper audio decodeinput" + decodeinput + " dataSize" + readSampleData + " sampeTime" + extractor.getSampleTime());
extractor.advance();
} else {
decoder.queueInputBuffer(inputIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
System.out.println("videoCliper audio decodeInput end");
inputDone = true;
}
}
}
журнал ошибок: 2020-03-28 14:49:22.549 32612-2052/com.srwl.mytx E/MPEG4Writer: The number of recorded samples is 0
2020-03-28 14:49:22.550 32612-2053/com.srwl.mytx I/MPEG4Writer: Received total/0-length (999/0) buffers and encoded 998 frames. - Video
2020-03-28 14:49:22.550 32612-2052/com.srwl.mytx E/MPEG4Writer: Dumping Audio track's last 10 frames timestamp and frame type
2020-03-28 14:49:22.550 32612-2052/com.srwl.mytx W/MPEG4Writer: 0-duration samples found: 1
2020-03-28 14:49:22.550 32612-2052/com.srwl.mytx W/MPEG4Writer: 0-duration samples found: 1
2020-03-28 14:49:22.550 32612-2052/com.srwl.mytx I/MPEG4Writer: Received total/0-length (0/0) buffers and encoded 0 frames. - Audio
2020-03-28 14:49:22.550 32612-2052/com.srwl.mytx I/MPEG4Writer: Audio track drift time: 0 us
2020-03-28 14:49:22.558 32612-2006/com.srwl.mytx E/AndroidRuntime: FATAL EXCEPTION: pool-7-thread-2
Process: com.srwl.mytx, PID: 32612
java.lang.IllegalStateException: Failed to stop the muxer
at android.media.MediaMuxer.nativeStop(Native Method)
Надеюсь кто-то может сказать мне, что пошло не так. Спасибо