GStreamer in OpenCV does not send video data over UDP

I'm trying to use GStreamer on Mac (10.12.6) to stream a video encoded from OpenCV frames via UDP. For some reason this does not work and I'm not getting any error output from GStreamer or OpenCV. This is how I open the writer in OpenCV:

    cv::VideoWriter writer(
    "appsrc ! videoconvert ! x264enc byte-stream=true threads=4 ! mpegtsmux ! udpsink host=localhost port=9999",
    cv::CAP_GSTREAMER,
    0,
    (double) 5,
    cv::Size(320, 240),
    true);

This writer opens and I can feed frames into it but I don't get any output when listening to the port. The same pipeline works when compiled from (c++) source using the GStreamer API or when being launched via

/gst-launch-1.0 videotestsrc ! x264enc byte-stream=true threads=4 ! mpegtsmux ! udpsink host=localhost port=9999

I don't think OpenCV or GStreamer itself is at fault because I am able to stream video to the autovideosink in OpenCV when opening the writer via

    cv::VideoWriter writer(
    "appsrc ! autovideosink",
    cv::CAP_GSTREAMER,
    0,
    (double) 5,
    cv::Size(320, 240),
    true);

For reference - I installed GStreamer via Brew and built OpenCV myself using the following CMake Flags:

-DOPENCV_ENABLE_NONFREE=ON
-DWITH_OPENGL=ON 
-DWITH_OPENVX=ON 
-DWITH_OPENCL=ON 
-DBUILD_PNG=ON 
-DBUILD_TIFF=ON 
-DOPENCV_EXTRA_MODULES_PATH=~/src/opencv_contrib/modules 
-DWITH_1394=OFF 
-DWITH_CUDA=OFF 
-DWITH_GSTREAMER=ON.

I'm relatively new to GStreamer so I could be missing something obvious. Any idea what I could be doing wrong here or what would help to track down the issue?


Finally got it. Turning on GStreamer Debug Output via setting GST_DEBUG=2 yielded that x264enc was not found by OpenCV. I didn't notice that as it was found when compiling the pipeline via the GStreamer C++ API.

The reason for that was that while the GStreamer install packages on OSX installed the x264enc element, brew on mac didn't. Having compiled OpenCV myself - it used the brew install of GStreamer and not the framework.

Solved the problem by reinstalling the x264enc element for GStreamer via brew (brew install gst-plugins-ugly --with-x264).

链接地址: http://www.djcxy.com/p/25436.html

上一篇: 为什么结果因大括号放置而异?

下一篇: OpenCV中的GStreamer不通过UDP发送视频数据