c++ - 通过VideoWriter发送帧;无法再次捕捉到它(OpenCV 3.1,c++)

标签 c++ opencv gstreamer

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

  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 的支持文档。 有什么问题吗?

最佳答案

在使用 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 

关于c++ - 通过VideoWriter发送帧;无法再次捕捉到它(OpenCV 3.1,c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47037987/

相关文章:

c++ - 从网络摄像头捕获视频时如何加快 IMediaControl::Run() 的速度?

c++ - 是否有可能在构造函数和析构函数之外修改 `vptr`?

c++ - 具有公共(public)链接的非 POD 对象 : what's supposed to happen?

c++ - 使用 __int16(或 int16_t)优于 int 的优点/缺点

java - Opencv 背景减法不检测带有小阵雪的视频的移动物体

python-3.x - 查找图像中的主线(及其角度)

opencv - 使用 OpenCV 消除闪烁?

c# - 在 WinForms 中显示 gstreamer-sharp 视频流

c++ - 使用 GStreamer 和 multiudpsink 设置不同的 RTP SSRC

gstreamer - 如何将 flv 文件(由 gstreamer flvmux 编码,包含带有 aac 音频的 h264 视频)流式传输到 rtmp 服务器而不解码?