本文介绍了通过VideoWriter发送帧;无法再次捕获它(OpenCV 3.1,C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to write a simple video streaming application that performs the following tasks:

  1. 从相机获取一个框架,该部件正在工作);
  2. 修改框架;
  3. 发送到gstreamer管道.
  1. Get a frame from camera this part is working);
  2. Modify frame;
  3. Send to a gstreamer pipeline.

代码:

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 player can't see anything with command:

vlc -vvv rtp://@localhost:5000

我尝试过:

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

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

But it didn't start (no error log, just didn't get any frame).I am using OpenCV 3.1, and I have read the support documentation for GStreamer.What can be wrong?

推荐答案

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

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

工作管道:

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 

这篇关于通过VideoWriter发送帧;无法再次捕获它(OpenCV 3.1,C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 22:35