OpenCV 4.2.0 C++ - H264 Encoding and Streaming - c++

Currently, i'm using OpenCV 4.2 C++ in order to encode and stream outputs from a Allied Vision Manta camera.
I already can grabe a frame, compress with MJPEG and the stream to other pipeline using OpenCV and GStreamer.
However, i need to try with H.264 (and later with H.265) but it's not working. The pipelines created are these in VideoWriter function are the follow:
1 - "appsrc ! queue ! videoconvert ! x264enc ! rtph264pay ! udpsink host=127.0.0.1 port=5015";
2 - "appsrc ! autovideoconvert ! videoconvert ! x264enc ! rtph264pay ! udpsink host=127.0.0.1 port=5015";
With the 1st pipe, i get:
[ WARN:0] global /opt/opencv/modules/videoio/src/cap_gstreamer.cpp (1759) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module x264enc0 reported: Can not initialize x264 encoder.
[ WARN:0] global /opt/opencv/modules/videoio/src/cap_gstreamer.cpp (1665) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
With the 2nd pipe, I get:
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/vmwgfx_drv_video.so
libva info: va_openDriver() returns -1
The others arguments of VideoWritter are:
cv::CAP_GSTREAMER, 0, 5, Size(1080, 720), true
The input pixel format is BGR, because i need to grab the frames with BayerRG8, and then convert to BGR to minimize the traffic.
The receiver is done with
udpsrc port=5015 ! application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264,framerate=15/1 ! rtph264depay ! decodebin ! videoconvert ! appsink
One detail that i don't know if it's important or not, i'm doing this in the VirtualBox.

Related

Can't get audio over GStreamer udpsrc element

I'm trying to play audio (WAV) file using Gstreamer udpsrc element with no success. Playing audio from a file works just fine:
gst-launch-1.0 -v filesrc location=sp5.wav ! wavparse ! audioconvert ! volume volume=1 ! autoaudiosink
But when running this in one terminal:
gst-launch-1.0 -v udpsrc port=5200 ! wavparse ! audioconvert ! volume volume=1 ! autoaudiosink
and this in another:
$ gst-launch-1.0 -v filesrc location=sp5.wav ! udpsink host=localhost port=5200
can't get any audio out (and Wireshark shows packets are going across). Trying the last command from a different PC didn't make any difference.
Running Gstreamer version 1.14.4.
Am i missing something obvious?

Gstreamer: error when decoding video stream

Hello I am trying to encode and decode a "live" video using the webcam of and windows pc. The gstreamer version that I am currently using is 1.15.1
For the encoding line I use:
gst-launch-1.0 ksvideosrc ! \
'video/x-raw, width=640, height=480, framerate=30/1' ! \
videoconvert ! \
x264enc pass=qual quantizer=20 tune=zerolatency ! \
rtph264pay ! \
filesink location=D:\\cam.ts
This make a file on the D drive, but when is try to decode it I get an error.
line used:
gst-launch-1.0 filesrc location=D:\\cam.ts ! \
rtph264depay ! \
avdec_h264 ! \
videoconvert ! \
autovideosink sync=false
This is the answer Gstreamer gives me
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
ERROR: from element /GstPipeline:pipeline0/GstFileSrc:filesrc0: Internal data stream error.
Additional debug info:
../libs/gst/base/gstbasesrc.c(3064): gst_base_src_loop ():
/GstPipeline:pipeline0/GstFileSrc:filesrc0:
streaming stopped, reason error (-5)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

gstreamer WARNING: erroneous pipeline

I am currently getting the following error
WARNING: erroneous pipeline: no element "Qtdemux" when I run the following command
gst-launch-1.0 -v filesrc location=~/Desktop/Dog.mp4 ! Qtdemux ! h264parse ! ffdec_h264 ! ffmpegcolorspace ! x264enc ! rtph264pay ! udpsink host=127.0.0.1 port=5000
I have tried making sure I have gstreamer-plugin-good and get the following response
gstreamer1.0-plugins-good is already the newest version (1.8.3-1ubuntu0.4).
However when I look at gst-inspect-1.0 Qtdemux I get the following response No such element or plugin 'Qtdemux'.
Any thoughts on what may be the problem I am facing?
It is qtdemux, with a samll q.

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).

gstreamer videotestsrc rtp not working

I have been trying to get gstreamer rtp working on my osx lion I have following:
sender:
gst-launch-1.0 videotestsrc ! avenc_mpeg4 ! rtpmp4vpay ! udpsink -vvv
receiver:
gst-launch-1.0 udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)MP4V-ES, profile-level-id=(string)1, config=(string)000001b001000001b58913000001000000012000c48d8800f50a041e1463000001b24c61766335332e33352e30, payload=(int)96, ssrc=(uint)1613325455, timestamp-offset=(uint)3778351903, seqnum-offset=(uint)5013" ! rtpmp4vdepay ! avdec_mpeg4 ! autovideosink
but all i get is a green screen on the receiver. Am i setting up my pipelines incorrectly?
I tried using the tcpserversink and tcpclientsrc as follows:
gst-launch-1.0 videotesavenc_mpeg4 ! rtpmp4vpay config-interval=2 ! tcpserversink port=5555 -vvv --gst-debug=3
gst-launch-1.0 tcpclientsrc port=5555 ! "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)MP4V-ES, profile-level-id=(string)1, config=(string)000001b001000001b58913000001000000012000c48d8800f50a041e1463000001b24c61766335332e33352e30, payload=(int)96, ssrc=(uint)970028597, timestamp-offset=(uint)2609711508, seqnum-offset=(uint)59228" ! rtpmp4vdepay ! decodebin ! videoconvert ! autovideosink --gst-debug=3 -vvv
which results in a flickering test source and the following error repeated on the client side:
0:00:06.213137000 10134 0x7fab6b051680 ERROR libav :0:: Error at MB: 311
0:00:06.214311000 10134 0x7fab6b051680 ERROR libav :0:: ac-tex damaged at 19 14
can someone construct a test pipeline to output the videotestsrc to mpeg4 video with both a sender and receiver please??
Try setting "host" for the udpsink like this:
gst-launch-1.0 videotestsrc ! avenc_mpeg4 ! rtpmp4vpay ! udpsink host=127.0.0.1 -vvv