Regarding writing opencv matrix to gstreamer pipeline?

Hi I’m currently trying to opencv matrix to gstreamer pipeline, although I can get the pipeline working using jpegenc I would like to have h264 encoded stream. The pipeline is as follows,

"appsrc ! videoscale ! videoconvert ! video/x-raw(memory:NVMM), format=I420,width=1920,height=1080,framerate=30/1 ! h264parse ! rtph264pay ! udpsink host= port=5001"

The issue with this being,

Streamer warning: error opening writer pipeline: could not link videoconvert0 to h264parse0, h264parse0 can't handle caps video/x-raw(memory:NVMM), format=(string)I420, width=(int)1920, height=(int)1080, framerate=(fraction)30/1

Any idea how to fix this? Thanks.

What data do you feed to appsrc? Compressed h264 data or raw I420 format video data?

If it is h264 data, the videoscale and videoconvert can not work correctly since compressed data can not be scaled or transformed to other format. The capsfilter is also wrong, the caps should be “video/x-h264” but not “video/x-raw(memory:NVMM)”.

If it is raw I420 data, there is no h264 encoder to compress the I420 raw data to h264 stream, so the h264parse and the plugins follow it can not work.

@Fiona.Chen, I’m currently trying to modify the code from this link that I had posted earlier. Is there a way to encode them as h264/h265. If yes could you please let me know how to achieve the same. Please take a look at the link and let me know if you need any other info.

I would be pushing opencv matrix into appsrc. The older pipeline in the link that I shared above seemed to be working fine in terms of streaming but DS has issues with jpeg encoded stream because of rtspsrc I believe. Hence wanted to encode in a different format.


What is the format of your opencv matrix? YUV data or RGB data? What is the size and layout?
Which NV platform is you working on? DGPU or Jetson?

I’m currently reading opencv frames as RGB data. the size is 1920 *1080. I’m not sure what layout means. I’m currently using DGPU. Not sure if I would be using a Jetson device, but if I tend to do it what issue could arise?

The format is important. There are software video encoder and hardware accelerated video encoder available in DGPU platform. “gst-inspect-1.0” command can help you to find the available h264 encoders. If the format match the encoder plugin’s sink pad caps, then the data can be encoded directly, if it is not, video format convert is needed before encoding.
Deepstream hardware accelerated H264 encoder is
Please refer to Deepstream sample codes for more details.