【问题标题】:Sending frame by VideoWriter; can't catching it again (OpenCV 3.1, c++)VideoWriter发送帧;无法再次捕捉到它(OpenCV 3.1,c++)
【发布时间】:2018-04-12 18:35:42
【问题描述】:

我正在尝试编写一个简单的视频流应用程序来执行以下任务:

  1. 从相机获取帧,这部分正在工作);
  2. 修改框架;
  3. 发送到gstreamer 管道。

代码:

VideoWriter writer;
writer.open("appsrc ! rtpvrawpay !  host =localhost port=5000" , 0, 30, cv::Size(IMAGE_WIDTH, IMAGE_HEIGHT), true);
while(true){

    //get frame etc.
    writer.write(frame);
}

VLC 播放器用命令看不到任何东西:

vlc -vvv rtp://@localhost:5000

我试过了:

cv::VideoCapture cap("udpsrc port=5000 ! tsparse ! videoconvert ! appsink");

但它没有启动(没有错误日志,只是没有得到任何帧)。 我正在使用 OpenCV 3.1,并且我已经阅读了 GStreamer 的支持文档。 有什么问题?

【问题讨论】:

  • 你能显示更多代码吗?目前尚不清楚frames 来自哪里。
  • 我有一个关于 Gstream 和他们应用于帧的过滤器的问题。你能检查一下这个问题吗stackoverflow.com/questions/47848575/…

标签: c++ opencv gstreamer


【解决方案1】:

问题是我的 openCV 版本不支持 gstreamer 的 VideoWriter。我把它改成 3.3.0 就可以了。

【讨论】:

    【解决方案2】:

    在使用 OpenCV 的 Gstreamer API 之前,使用 Gstreamer 的命令行工具拥有一个工作管道非常重要。

    发件人:

    工作管道:

    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 代码:

    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;
    }
    

    接收方:

    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 
    

    【讨论】:

    • 这似乎是自 OpenCV 3.3.0 以来的新功能(the documentation 的先前版本未提及替代后端)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 2017-07-27
    • 2018-02-13
    • 2017-02-10
    相关资源
    最近更新 更多