Mobile-SDK-Android icon indicating copy to clipboard operation
Mobile-SDK-Android copied to clipboard

How can we receive the video stream as RGB? There is a callback for yuv but no callback for RGB

Open samanazadpour opened this issue 4 years ago • 10 comments

How can we get the video stream as RGB? Would you please write some sample code for us.

samanazadpour avatar Nov 10 '21 01:11 samanazadpour

Agent comment from DJI SDK in Zendesk ticket #56069:

尊敬的开发者,感谢您联系DJI 大疆创新 由于github不是我们主要的咨询渠道,您的问题可能跟进不及时。我们建议您通过填写表单( https://djisdksupport.zendesk.com/hc/zh-cn/requests/new )向我们反馈问题。或者您也可以在论坛发帖,与其它开发者交流。论坛链接:https://djisdksupport.zendesk.com/hc/zh-cn/community/topics

Dear developer, thank you for contacting DJI. Since github is not our main consultation channel, your questions may not be followed up in time. We recommend that you fill in the form (https://djisdksupport.zendesk.com/hc/en-us/requests/new) to report problems to us. Or you can post in the forum to communicate with other developers. Forum link: https://djisdksupport.zendesk.com/hc/zh-cn/community/topics

°°°

dji-dev avatar Nov 10 '21 01:11 dji-dev

Currently you can only call getRgbaData when everytime the YuvDataCallback is called, this is the only way to get RGB data.

DJI-William avatar Nov 10 '21 06:11 DJI-William

Thank you so much for your quick reply. Would you please write some sample code here or let us know where is the best place to implement getRgbaData function.

samanazadpour avatar Nov 10 '21 08:11 samanazadpour

Although this demo does not contain getRgbaData function but I think it will give you some hint in terms of decoding. Link:https://github.com/DJI-Mobile-SDK-Tutorials/Android-VideoStreamDecodingSample

By the way, may I ask why you need to use RGB data, beacause people are more often using YUV data. Smaller and more efficient than RGB data.

DJI-William avatar Nov 10 '21 09:11 DJI-William

I need to get the byte stream of RGB to pass it to my encoder to transmit it to my video streaming service. We have implemented getRgbaData into onYuvdatarecieved callback but it does not return buffer. It is always null. Where is the right place to call this getRgbaData?

samanazadpour avatar Nov 10 '21 10:11 samanazadpour

Is this implementation correct?

                mCodecManager.enabledYuvData(true);
                mCodecManager.setYuvDataCallback(new DJICodecManager.YuvDataCallback() {
                    @Override
                    public void onYuvDataReceived(MediaFormat mediaFormat, ByteBuffer yuvFrame, int dataSize, int width, int height) {
                        Log.d(TAG, "onYuvDataReceived - data size: " + dataSize);
                        if (System.currentTimeMillis() - lastupdate > 1000) {
                            //   Log.d(TAG, "current fps is: " + fps);
                            //   fps = 0;
                            lastupdate = System.currentTimeMillis();
                        }
                        if (yuvFrame != null) {
                            fps++;

                            //lastupdate = TimeUnit.MICROSECONDS.toNanos(SystemClock.elapsedRealtime());
                            final byte[] bytes = new byte[dataSize];
                            yuvFrame.get(bytes);


                            byte[] buffer =mCodecManager.getRgbaData(width, height);
                            Log.d(TAG, "buffer :"+buffer);


                        }
                    }
                });

samanazadpour avatar Nov 10 '21 10:11 samanazadpour

I think it is correct. Are you able to get YuvData in the Yuvdata callback? If you cannot get RGB data in this callback then I think this function is faulty. We havn't maintainese this function for a long time.

DJI-William avatar Nov 10 '21 11:11 DJI-William

We are not able to get YuvData as well. getYuvdata also returns null.

samanazadpour avatar Nov 10 '21 11:11 samanazadpour

I think you cannot get proper video stream yet. Have a look this demo below, make sure you can get YuvData first, then seek for RGB. You have to make sure you can get data in VideoDataListener callback and sendDataToDocoder. Link:https://github.com/DJI-Mobile-SDK-Tutorials/Android-VideoStreamDecodingSample

DJI-William avatar Nov 12 '21 02:11 DJI-William

First, you can print the [datasize] which should be of length 1382400 to confirm if things are proper. Next take the bytes as an array from the yuvdatacallback and and use YUV420p2RGB for RGB conversion to get frames back at 1280x720 resolution.

if (count++ % 3 == 0 && yuvFrame != null) { final byte[] bytes = new byte[dataSize]; yuvFrame.get(bytes);

The above code will give you 10 fps and you can chage the count value to get more or less fps.
You can also send these bytes as an array to a python server and use openCV for conversion and streaming.

Rakesh-John avatar Feb 06 '22 15:02 Rakesh-John