从 DJI 无人机解码 Android 上的视频流
Decoding video stream on Android from DJI drone
您好,我想对来自 DJI phantom 3 pro 的视频流使用 OpenCv 进行一些图像处理。不幸的是,这件事需要制作自己的解码视频。我知道它应该与 use Media Codec Android class 一起使用,但我不知道该怎么做。我看到了一些从视频文件解码视频的例子,但我无法为我的目的修改这段代码。有人可以展示一些示例或教程如何做吗?感谢帮助
mReceivedVideoDataCallBack = new DJIReceivedVideoDataCallBack(){
@Override
public void onResult(byte[] videoBuffer, int size){
//recvData = true;
//DJI methods for decoding
//mDjiGLSurfaceView.setDataToDecoder(videoBuffer, size);
}
};
这是从无人机发送编码流的方法,我需要发送解码videoBuffer然后修改为OpenCV的Mat。
像这样初始化视频回调
mReceivedVideoDataCallBack = new DJICamera.CameraReceivedVideoDataCallback() {
@Override
public void onResult(byte[] videoBuffer, int size) {
if(mCodecManager != null){
// Send the raw H264 video data to codec manager for decoding
mCodecManager.sendDataToDecoder(videoBuffer, size);
}else {
Log.e(TAG, "mCodecManager is null");
}
}
}
让你的activity实现TextureView.SurfaceTextureListener
对于 TextureView mVideoSurface,在初始化后调用此行:
mVideoSurface.setSurfaceTextureListener(this);
然后执行:
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.v(TAG, "onSurfaceTextureAvailable");
DJICamera camera = FPVDemoApplication.getCameraInstance();
if (mCodecManager == null && surface != null && camera != null) {
//Normal init for the surface
mCodecManager = new DJICodecManager(this, surface, width, height);
Log.v(TAG, "Initialized CodecManager");
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.v(TAG, "onSurfaceTextureSizeChanged");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.v(TAG, "onSurfaceTextureDestroyed");
if (mCodecManager != null) {
mCodecManager.cleanSurface();
mCodecManager = null;
}
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
final Bitmap image = mVideoSurface.getBitmap();
//Do whatever you want with the bitmap image here on every frame
}
希望对您有所帮助!
您好,我想对来自 DJI phantom 3 pro 的视频流使用 OpenCv 进行一些图像处理。不幸的是,这件事需要制作自己的解码视频。我知道它应该与 use Media Codec Android class 一起使用,但我不知道该怎么做。我看到了一些从视频文件解码视频的例子,但我无法为我的目的修改这段代码。有人可以展示一些示例或教程如何做吗?感谢帮助
mReceivedVideoDataCallBack = new DJIReceivedVideoDataCallBack(){
@Override
public void onResult(byte[] videoBuffer, int size){
//recvData = true;
//DJI methods for decoding
//mDjiGLSurfaceView.setDataToDecoder(videoBuffer, size);
}
};
这是从无人机发送编码流的方法,我需要发送解码videoBuffer然后修改为OpenCV的Mat。
像这样初始化视频回调
mReceivedVideoDataCallBack = new DJICamera.CameraReceivedVideoDataCallback() {
@Override
public void onResult(byte[] videoBuffer, int size) {
if(mCodecManager != null){
// Send the raw H264 video data to codec manager for decoding
mCodecManager.sendDataToDecoder(videoBuffer, size);
}else {
Log.e(TAG, "mCodecManager is null");
}
}
}
让你的activity实现TextureView.SurfaceTextureListener 对于 TextureView mVideoSurface,在初始化后调用此行:
mVideoSurface.setSurfaceTextureListener(this);
然后执行:
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.v(TAG, "onSurfaceTextureAvailable");
DJICamera camera = FPVDemoApplication.getCameraInstance();
if (mCodecManager == null && surface != null && camera != null) {
//Normal init for the surface
mCodecManager = new DJICodecManager(this, surface, width, height);
Log.v(TAG, "Initialized CodecManager");
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.v(TAG, "onSurfaceTextureSizeChanged");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.v(TAG, "onSurfaceTextureDestroyed");
if (mCodecManager != null) {
mCodecManager.cleanSurface();
mCodecManager = null;
}
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
final Bitmap image = mVideoSurface.getBitmap();
//Do whatever you want with the bitmap image here on every frame
}
希望对您有所帮助!