安卓上从DJI无人机解码视频流

6

你好,我想使用OpenCV对来自DJI Phantom 3 Pro的视频流进行图像处理。不幸的是,必须制作自己的视频解码器。我知道应该使用Media Codec Android类来实现此功能,但我不知道如何操作。我看到了一些从视频文件解码视频的示例,但我无法修改这段代码以实现我的目标。有人可以给我展示一些示例或教程吗?感谢帮助。

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

这是从无人机发送编码流的方法,我需要发送videoBuffer进行解码,然后将其修改为OpenCV中的Mat格式。

1个回答

4

像这样初始化视频回调

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初始化后调用此行:
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
    }

希望这有帮助!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接