Sending frame by VideoWriter; can't catching it again (OpenCV 3.1, c++)

我的梦境 提交于 2019-11-28 14:19:43

Before using OpenCV's Gstreamer API, it's important that you have a working pipeline, using Gstreamer's commandline tool.

Sender:

Working pipeline:

gst-launch-1.0 -v v4l2src \
! video/x-raw, framerate=30/1, width=640, height=480, format=BGR \
! videoconvert ! video/x-raw, format=I420, width=640, height=480, framerate=30/1 \
! rtpvrawpay ! udpsink host=127.0.0.1 port=5000

OpenCV code:

bool sender()
{
    VideoCapture cap = VideoCapture("v4l2src ! video/x-raw, framerate=30/1, width=640, height=480, format=BGR ! appsink",cv::CAP_GSTREAMER);
    VideoWriter out = VideoWriter("appsrc ! videoconvert ! video/x-raw, format=I420, width=640, height=480, framerate=30/1 ! rtpvrawpay ! udpsink host=127.0.0.1 port=5000",CAP_GSTREAMER,0,30,Size(640,480));

    if(!cap.isOpened() || !out.isOpened())
    {
        cout<<"VideoCapture or VideoWriter not opened"<<endl;
        return false;
    }

    Mat frame;

    while(true)
    {
        cap.read(frame);

        if(frame.empty())
            break;

       /* Modify frame here*/

        out.write(frame);

        imshow("frame", frame);
        if(waitKey(1) == 'q')
            break;
    }

    cap.release();
    out.release();
    return true;
}

Receiver:

gst-launch-1.0 -v udpsrc port=5000 \
! "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:0, depth=(string)8, width=(string)640, height=(string)480, payload=(int)96" \
! rtpvrawdepay ! xvimagesink 

The problem was that my openCV's version didn't support gstreamer's VideoWriter. I change it to 3.3.0 and it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!