gpt4 book ai didi

audio - 混合音频和视频,停止MediaMuxer时出现问题

转载 作者:行者123 更新时间:2023-12-03 01:22:04 24 4
gpt4 key购买 nike

当我使用mediacodec音频合并到视频中时,我只想在调用android时从音频的10 s中捕获一个片段。媒体。 MediaExtractor#seekTo,引入10 s参数后,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)

我希望有人能告诉我出了什么问题。谢谢

最佳答案

问题已经解决。

像这样 :

  outputInfo.presentationTimeUs -= startPosition;
if (outputInfo.presentationTimeUs > lastEncodeOutputTimeStamp) {
encodeoutput++;
System.out.println("videoCliper audio encodeOutput" + encodeoutput + " dataSize" + outputInfo.size + " sampeTime" + outputInfo.presentationTimeUs);
mMediaMuxer.writeSampleData(muxAudioTrack, encodedData, outputInfo);
lastEncodeOutputTimeStamp = outputInfo.presentationTimeUs;
}

pts写入mediamuxer需要从开始时间减去

关于audio - 混合音频和视频,停止MediaMuxer时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60898170/

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