OpenCV 4.2.0 C++ - H264 Encoding and Streaming

1.1k views Asked by At

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.

0

There are 0 answers