Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch the video mode from the h20 camera to the BGR format. #878

Closed
IvanOrfanidi opened this issue Mar 28, 2022 · 6 comments
Closed

Switch the video mode from the h20 camera to the BGR format. #878

IvanOrfanidi opened this issue Mar 28, 2022 · 6 comments

Comments

@IvanOrfanidi
Copy link

Hello!
Can You help me?
I want to switch the video mode from the camera H20.
Now mode is RGBA
converterToAppSink = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "RGBA", nullptr);

How can I switch the H20 to BGR?

Thank you for your help!

@dji-dev
Copy link
Contributor

dji-dev commented Mar 28, 2022

Agent comment from DJI SDK in Zendesk ticket #62150:

尊敬的开发者,感谢您联系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

°°°

@IvanOrfanidi
Copy link
Author

IvanOrfanidi commented Mar 28, 2022

if (pipeline == nullptr) { throw std::runtime_error("failed to create pipeline"); }

appSrc = gst_element_factory_make("appsrc", "source");
if (appSrc == nullptr) { throw std::runtime_error("failed to create app source"); }

h264InputParser = gst_element_factory_make("h264parse", "input h264 parser");
if (h264InputParser == nullptr) { throw std::runtime_error("failed to create input h264 parser"); }

decoder = gst_element_factory_make("omxh264dec", "decoder");
if (decoder == nullptr) { throw std::runtime_error("failed to create decoder"); }

decodeConverter = gst_element_factory_make("nvvidconv", "decode converter");
if (decodeConverter == nullptr) { throw std::runtime_error("failed to create decode converter"); }

loop = g_main_loop_new(nullptr, false);
if (loop == nullptr) { throw std::runtime_error("failed to create loop"); }

bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
if (bus == nullptr) { throw std::runtime_error("failed to get bus from pipeline"); }

appSink = gst_element_factory_make("appsink", "app sink");
if (appSink == nullptr) { throw std::runtime_error("failed to create app sink"); }
  

@IvanOrfanidi
Copy link
Author

srcToParser =
  gst_caps_new_simple("video/x-h264", "stream-format", G_TYPE_STRING, "byte-stream", "alignment", G_TYPE_STRING, "nal", nullptr);
if (srcToParser == nullptr) { throw std::runtime_error("failed to init source to parser caps"); }

converterToAppSink = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "RGBA", nullptr);
if (converterToAppSink == nullptr) { throw std::runtime_error("failed to create converter to sink caps"); }

nvvidconvToConverter = gst_caps_new_empty_simple("video/x-raw");
if (nvvidconvToConverter == nullptr) { throw std::runtime_error("failed to create converter to sink caps"); }

auto feature = gst_caps_features_new("memory:NVMM", nullptr);
if (feature == nullptr) { throw std::runtime_error("failed to init feature"); }

gst_caps_set_features(nvvidconvToConverter, 0, feature);

}

@IvanOrfanidi
Copy link
Author

auto self = static_cast<Decoder*>(data);
if (self == nullptr) { return GST_FLOW_EOS; }

GstSample* sample = gst_app_sink_pull_sample(GST_APP_SINK(appSink));
GstCaps* caps = gst_sample_get_caps(sample);
GstBuffer* buffer = gst_sample_get_buffer(sample);
GstStructure* structure = gst_caps_get_structure(caps, 0);
const int width = g_value_get_int(gst_structure_get_value(structure, "width"));
const int height = g_value_get_int(gst_structure_get_value(structure, "height"));
g_value_get_string(gst_structure_get_value(structure, "format"));

if (!self->capsPrinted) {
  INFO("caps: %s\n", gst_caps_to_string(caps));
  self->capsPrinted = true;
}

// Get frame data
GstMapInfo map;
if (!gst_buffer_map(buffer, &map, GST_MAP_READ)) { return GST_FLOW_ERROR; }

cv::Mat img(cv::Size(width, height), CV_8UC4, map.data);

cv::cvtColor(img, img, CV_RGBA2BGR);

self->decodedFrameQueue.push(img);

gst_buffer_unmap(buffer, &map);
gst_sample_unref(sample);

@dji-dev
Copy link
Contributor

dji-dev commented Mar 29, 2022

Agent comment from kyle.cai in Zendesk ticket #62150:

Dear developer ,

Thank you for contacting DJI.

The video format OSDK get from the drone is H264, and sample decode the H264 to RGB using ffmpeg, you can change this part of code.

pSwsCtx = sws_getContext(w, h, pCodecCtx->pix_fmt,

Thank you for your understanding and support, hope you have a nice day.

Best Regards,
DJI SDK Support Team

°°°

@IvanOrfanidi
Copy link
Author

Thanks!
I am always glad of your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants