【问题标题】:Decoding video stream on Android from DJI drone从 DJI 无人机解码 Android 上的视频流
【发布时间】:2016-02-05 00:26:18
【问题描述】:

您好,我想使用 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解码,然后修改为Mat for OpenCV。

【问题讨论】:

    标签: android opencv video decoding


    【解决方案1】:

    像这样初始化视频回调

    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
        }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多