DJI Mobile SDK를 통해 무인항공기의 영상 흐름 전송을 통해 YUV 이미지를 얻다
9845 단어 yuvDJIdronedecodevideostream
DJI UX SDK
DJI UX SDK 간단한 설치 절차를 통해 드론의 영상 흐름 전송과 드론 조작의 UI를 응용 프로그램에 가져올 수 있다.
영상 흐름 매체에서 YUV 이미지를 얻다
Android Video Stream Decoding Sample 샘플은 영상 흐름 전송을 디코딩하고 YUV 이미지를 출력한다.
1. SurfaceTexture에 이미지 표시 및 디코더 생성
/**
* Init a fake texture view to for the codec manager, so that the video raw data can be received
* by the camera
*/
private void initPreviewerTextureView() {
videostreamPreviewTtView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.d(TAG, "real onSurfaceTextureAvailable");
videoViewWidth = width;
videoViewHeight = height;
Log.d(TAG, "real onSurfaceTextureAvailable: width " + videoViewWidth + " height " + videoViewHeight);
if (mCodecManager == null) {
mCodecManager = new DJICodecManager(getApplicationContext(), surface, width, height);
//For M300RTK, you need to actively request an I frame.
mCodecManager.resetKeyFrame();
}
}
});
}
2. 디코더에 YuvDataCallback 등록
mCodecManager.enabledYuvData(true);
mCodecManager.setYuvDataCallback(this);
3. 디코딩된 YUV 이미지 수신
@Override
public void onYuvDataReceived(MediaFormat format, final ByteBuffer yuvFrame, int dataSize, final int width, final int height) {
//In this demo, we test the YUV data by saving it into JPG files.
//DJILog.d(TAG, "onYuvDataReceived " + dataSize);
if (count++ % 30 == 0 && yuvFrame != null) {
final byte[] bytes = new byte[dataSize];
yuvFrame.get(bytes);
//DJILog.d(TAG, "onYuvDataReceived2 " + dataSize);
AsyncTask.execute(new Runnable() {
@Override
public void run() {
// two samples here, it may has other color format.
int colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
switch (colorFormat) {
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
//NV12
if (Build.VERSION.SDK_INT <= 23) {
oldSaveYuvDataToJPEG(bytes, width, height);
} else {
newSaveYuvDataToJPEG(bytes, width, height);
}
break;
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
//YUV420P
newSaveYuvDataToJPEG420P(bytes, width, height);
break;
default:
break;
}
}
});
}
}
Reference
이 문제에 관하여(DJI Mobile SDK를 통해 무인항공기의 영상 흐름 전송을 통해 YUV 이미지를 얻다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/k-koh/items/e572f377e16bd79e0812
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Android Video Stream Decoding Sample 샘플은 영상 흐름 전송을 디코딩하고 YUV 이미지를 출력한다.
1. SurfaceTexture에 이미지 표시 및 디코더 생성
/**
* Init a fake texture view to for the codec manager, so that the video raw data can be received
* by the camera
*/
private void initPreviewerTextureView() {
videostreamPreviewTtView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.d(TAG, "real onSurfaceTextureAvailable");
videoViewWidth = width;
videoViewHeight = height;
Log.d(TAG, "real onSurfaceTextureAvailable: width " + videoViewWidth + " height " + videoViewHeight);
if (mCodecManager == null) {
mCodecManager = new DJICodecManager(getApplicationContext(), surface, width, height);
//For M300RTK, you need to actively request an I frame.
mCodecManager.resetKeyFrame();
}
}
});
}
2. 디코더에 YuvDataCallback 등록
mCodecManager.enabledYuvData(true);
mCodecManager.setYuvDataCallback(this);
3. 디코딩된 YUV 이미지 수신
@Override
public void onYuvDataReceived(MediaFormat format, final ByteBuffer yuvFrame, int dataSize, final int width, final int height) {
//In this demo, we test the YUV data by saving it into JPG files.
//DJILog.d(TAG, "onYuvDataReceived " + dataSize);
if (count++ % 30 == 0 && yuvFrame != null) {
final byte[] bytes = new byte[dataSize];
yuvFrame.get(bytes);
//DJILog.d(TAG, "onYuvDataReceived2 " + dataSize);
AsyncTask.execute(new Runnable() {
@Override
public void run() {
// two samples here, it may has other color format.
int colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
switch (colorFormat) {
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
//NV12
if (Build.VERSION.SDK_INT <= 23) {
oldSaveYuvDataToJPEG(bytes, width, height);
} else {
newSaveYuvDataToJPEG(bytes, width, height);
}
break;
case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
//YUV420P
newSaveYuvDataToJPEG420P(bytes, width, height);
break;
default:
break;
}
}
});
}
}
Reference
이 문제에 관하여(DJI Mobile SDK를 통해 무인항공기의 영상 흐름 전송을 통해 YUV 이미지를 얻다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/k-koh/items/e572f377e16bd79e0812텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)