Opencv text video error

I run this code:

#include <gst/gst.h>
#include <opencv2/opencv.hpp>

int main(int argc, char *argv[]) {
    // Initialize GStreamer
    gst_init(&argc, &argv);

    // Create a GStreamer pipeline
    GstElement *pipeline = gst_pipeline_new("opencv-udp-pipeline");
    GstElement *source = gst_element_factory_make("appsrc", "video-source");
    GstElement *convert = gst_element_factory_make("videoconvert", "video-convert");
    GstElement *capsfilter = gst_element_factory_make("capsfilter", "capsfilter");
    GstElement *jpegenc = gst_element_factory_make("jpegenc", "jpeg-encoder");
    GstElement *payload = gst_element_factory_make("rtpjpegpay", "rtp-payload");
    GstElement *udpsink = gst_element_factory_make("udpsink", "udp-sink");

    if (!pipeline || !source || !convert || !capsfilter || !jpegenc || !payload || !udpsink) {
        g_print("One or more elements could not be created. Exiting.\n");
        return -1;

    // Set up the pipeline properties
    //g_object_set(source, "is-live", true, "do-timestamp", true, NULL);
    g_object_set(udpsink, "host", "", "port", 5000, NULL);  // Set your desired host and port

    // Set video format (adjust as needed)
    GstCaps *caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "BGR", "width", G_TYPE_INT, 640, "height", G_TYPE_INT, 480, NULL);
    g_object_set(capsfilter, "caps", caps, NULL);

    // Add elements to the pipeline
    gst_bin_add_many(GST_BIN(pipeline), source,convert, capsfilter, jpegenc, payload, udpsink, NULL);

    // Link elements in the pipeline
    if (!gst_element_link(source, convert) ||
        !gst_element_link(convert, capsfilter) ||
        !gst_element_link(capsfilter, jpegenc) ||
        !gst_element_link(jpegenc, payload) ||
        !gst_element_link(payload, udpsink)) {
        g_print("Elements could not be linked. Exiting.\n");
        return -1;

    // Set the pipeline to the playing state
    GstStateChangeReturn ret1 = gst_element_set_state(pipeline, GST_STATE_PLAYING);

    if (ret1 == GST_STATE_CHANGE_FAILURE) {
        g_print("Unable to set the pipeline to the playing state. Exiting.\n");
        return -1;

    // Start OpenCV video capture and push frames to the GStreamer pipeline
    cv::VideoCapture cap(0,cv::CAP_V4L2);
    cv::Mat frame;

    while (true) {
        if (! {
            std::cerr << "Error: Could not read frame from OpenCV VideoCapture." << std::endl;
        std::string text = "Hello, World!";
        cv::putText(frame, text, cv::Point(10, 30), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 2);

        // Send the frame to GStreamer pipeline

        //cv::imshow("Video with Text", frame);

        // Push the frame to GStreamer pipeline
        GstBuffer *buffer;
        GstFlowReturn ret;

        buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY,, * frame.elemSize(), 0, * frame.elemSize(), nullptr, nullptr);
        g_signal_emit_by_name(source, "push-buffer", buffer, &ret);


        if (ret != GST_FLOW_OK) {
            g_print("Error pushing frame to pipeline. Exiting.\n");

        if (cv::waitKey(1) >= 0) {

    // Clean up
    gst_element_set_state(pipeline, GST_STATE_NULL);

    return 0;

This my GST_DEBUG error in my pipeline.What’s the problem in my pipeline ?

0:00:01.500470300  5991 0x56222936ff20 INFO        GST_ERROR_SYSTEM gstelement.c:2145:gst_element_message_full_with_details:<video-source> posting message: Internal data stream error.
0:00:01.500523715  5991 0x56222936ff20 INFO        GST_ERROR_SYSTEM gstelement.c:2172:gst_element_message_full_with_details:<video-source> posted error message: Internal data stream error.```

Which platform you’re using?

Ubuntu 18.04

Would like to confirm if you use Drive PX2 or other platform. The software release for Drive PX2 is in Ubuntu 16.04. But your system is 18.04. It is a bit confusing.

I use this platform but I develop this code in ubuntu 18.04 on oracle virtualbox

that seems to be Qualcomm platform, not our Jetson platforms

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.