desc:编码时间设置

main
xiaowusky 1 year ago
parent d915812236
commit 3ad25de4fe

@ -27,7 +27,7 @@ public class MediaCodecManager {
// parameters for the encoder
private static final String MIME_TYPE = "video/hevc"; // H.264 Advanced Video
//
private ArrayBlockingQueue<byte[]> frameBytes;
private ArrayBlockingQueue<TimedBuffer> frameBytes;
private MediaCodec mMediaCodec;
private int mColorFormat;
private MediaFormat mediaFormat;
@ -149,10 +149,11 @@ public class MediaCodecManager {
public void addFrameData(byte[] data) {
if (isStart && !isPause) {
boolean isOffer = frameBytes.offer(data);
TimedBuffer timedData = new TimedBuffer(data, System.nanoTime() / 1000);
boolean isOffer = frameBytes.offer(timedData);
if (!isOffer) {
frameBytes.poll();
frameBytes.offer(data);
frameBytes.offer(timedData);
}
}
}
@ -208,7 +209,7 @@ public class MediaCodecManager {
mMediaCodec.setCallback(new MediaCodec.Callback() {
@Override
public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) {
byte[] data = null;
TimedBuffer data = null;
try {
data = frameBytes.take();
} catch (InterruptedException e) {
@ -220,11 +221,11 @@ public class MediaCodecManager {
if (inputBuffer == null)
return;
inputBuffer.clear();
inputBuffer.put(data);
inputBuffer.put(data.buffer);
long currentTimeUs = (System.nanoTime() - mTime) / 1000;//通过控制时间轴,达到暂停录制,继续录制的效果
codec.queueInputBuffer(index, 0, data.length, currentTimeUs, 0);
codec.queueInputBuffer(index, 0, data.buffer.length, data.time, 0);
try {
Thread.sleep(0);
} catch (InterruptedException e) {
@ -345,4 +346,14 @@ public class MediaCodecManager {
return 12;
return 11;
}
class TimedBuffer {
byte[] buffer;
long time;
public TimedBuffer(byte[] data, long frameTime) {
buffer = data;
time = frameTime;
}
}
}

Loading…
Cancel
Save