微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从DJI无人机解码Android上的视频流

嗨,我想在DJI phantom 3 pro的视频流上使用OpenCv进行一些图像处理.不幸的是,这件事是必要的自己解码视频.我知道应该使用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.

最佳答案
像这样初始化视频回调

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,"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
    }

希望这可以帮助!

原文地址:https://www.jb51.cc/android/429889.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐