通过DJI无人机在Android上解码视频流 [英] Decoding video stream on Android from DJI drone

查看:822
本文介绍了通过DJI无人机在Android上解码视频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对来自DJI phantom 3 pro的视频流使用OpenCv进行一些图像处理.不幸的是,为此必须自己制作解码视频.我知道应该与使用Media Codec Android类一起使用,但我不知道该怎么做.我看到了一些用于解码视频文件中视频的示例,但出于我的目的,我无法修改此代码.有人可以显示一些示例或教程怎么做?感谢您的帮助

Hi I would like do some image processing with use OpenCv on video stream from DJI phantom 3 pro. Unfortunately for this thing is necessary making own decoding video. I know that it should be work with use Media Codec Android class but I dont know how to do. I saw some examples for decoding video from video file, but I wasn't able modify this code for my aim. Could somebody show some example or tutorial how to do? Thanks for help

mReceivedVideoDataCallBack = new DJIReceivedVideoDataCallBack(){
        @Override
        public void onResult(byte[] videoBuffer, int size){
            //recvData = true;
            //DJI methods for decoding              
            //mDjiGLSurfaceView.setDataToDecoder(videoBuffer, size);
        }
    };

这是一种从无人机发送编码流的方法,我需要发送该视频以对videoBuffer进行解码,然后将其修改为适用于OpenCV的Mat.

This is method which is sending encoding stream from drone, and I need to send for decode the videoBuffer and then modify to Mat for OpenCV.

推荐答案

像这样初始化视频回调

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");
                 }
            }        
}

使您的活动实现TextureView.SurfaceTextureListener 对于TextureView mVideoSurface,在初始化后调用此行:

Make your activity implement TextureView.SurfaceTextureListener and for the TextureView mVideoSurface call this line after it is initialized:

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无人机在Android上解码视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆