大疆MSDK5.8如何把YUM数据返回并实现视频实时观看
Completed5.8之前用的是这种方法
public YuvDataListener dji_yuv_data_callback_ = new YuvDataListener() {
@Override
public void onReceive(MediaFormat mediaFormat, byte[] data, int width, int height) {
if (is_rate_time) {
if (isPrintLog) {
isPrintLog = false;
ToolsUtil.getInstance().sendLog("YuvDataListener onReceive,width:" + width + ",height:" + height);
}
is_rate_time = false;
JavaI420Buffer buffer = JavaI420Buffer.allocate(width, height);
ByteBuffer dataY = buffer.getDataY();
ByteBuffer dataU = buffer.getDataU();
ByteBuffer dataV = buffer.getDataV();
final byte[] bytes = data;
int yLen = width * height;
int uLen = (width + 1) / 2 * ((height + 1) / 2);
int vLen = uLen;
int color_format = mediaFormat.getInteger(MediaFormat.KEY_COLOR_FORMAT);
switch (color_format) {
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
byte[] ubytes = new byte[uLen];
byte[] vbytes = new byte[vLen];
for (int i = 0; i < uLen; i++) {
ubytes[i] = bytes[yLen + 2 * i];
vbytes[i] = bytes[yLen + 2 * i + 1];
}
dataY.put(bytes, 0, yLen);
dataU.put(ubytes, 0, uLen);
dataV.put(vbytes, 0, vLen);
break;
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
int yPos = 0;
int uPos = yPos + yLen;
int vPos = uPos + uLen;
dataY.put(bytes, yPos, yLen);
dataU.put(bytes, uPos, uLen);
dataV.put(bytes, vPos, vLen);
break;
default:
break;
}
long captureTimeNs = TimeUnit.MILLISECONDS.toNanos(SystemClock.elapsedRealtime());
if (capturer_observer_ != null) {
VideoFrame videoFrame = new VideoFrame(buffer, 0, captureTimeNs);
capturer_observer_.onFrameCaptured(videoFrame);
videoFrame.release();
} else {
buffer.release();
}
}
}
};
5.8移除了这个方法,那我们该如何实现跟原来一样的功能呢?
-
你可以查看这篇教程:https://developer.dji.com/doc/mobile-sdk-tutorial/cn/tutorials/video-stream/video-stream2.html 5.8获取YUV数据的新接口是addFrameListener
Please sign in to leave a comment.
Comments
1 comment