Decoding video stream on Android from DJI drone

百般思念 提交于 2020-01-14 08:54:17

问题


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

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.


回答1:


Initialize the video callback like this

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

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

mVideoSurface.setSurfaceTextureListener(this);

and then implement:

    @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
    }

Hope this helps!



来源:https://stackoverflow.com/questions/33523053/decoding-video-stream-on-android-from-dji-drone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!