Jetson agx+gstreamer+sensor_msgs/image: using nvjpegenc/nvv4l2h264enc/rtph264pay/rtmpsinkto encode frames from sensor_msgs/image as appsrc

HI,I’m trying to write a C++ program in my Jetson AGX that does the following:
System version: jetpack 5.1.2

  1. Receive video from the camera and convert it as follows: camera->RGB-> sensor_msgs/image (data format of ros)
  2. For each image obtained (sensor_msgs/image): detect and/or track specific objects in it and draw a bounding box around the object.
  3. Output images with bounding boxes to the Gstreamer pipeline, which encodes these images into JPEGs, and then outputs these JPEGs to a certain receiver, such as TCPSoreSink. This is the first configuration. The second configuration is to convert as follows: sensor_msgs/image → h264/h265 → file/RTSP/RTMP,
    Steps 1 and 2 work well so far, but in step 3 I seem to get a “JPEG parameter structure mismatch” error from gstreamer (more details later when I’ll have access to my computer).

For step 1, I wrote the following code, which works fine:

std::ostringstream ss;
ss <<"nvv4l2camerasrc device=/dev/video0 ! video/x-raw(memory:NVMM), width=1920, height=1080,interlace-mode=progressive, framerate=30/1, format=UYVY! nvvidconv ! video/x-raw(memory:NVMM), format=(string)NV12 ! appsink name=raw_sink max-buffers=1 drop=true";
 std::string launch_str_ = ss.str();
  GError* err = NULL;
  // launch pipeline
  pipeline_ = gst_parse_launch(launch_str_.c_str(), &err);

Step 3 is to use NVJPEGENC to encode the frame from sensor_msgs/image to appsrc:

std::ostringstream ss;
ss << " appsrc name=raw_src is-live=true do-timestamp=true format=3 ! nvjpegenc ! appsink name=jpg_sink max-buffers=1 drop=true";
 std::string launch_str_ = ss.str();
  GError* err = NULL;
  // launch pipeline
  pipeline_ = gst_parse_launch(launch_str_.c_str(), &err);

However, in the third step, it is displayed: JPEG parameter struct mismatch: library thinks size is 584, caller expects 720, causing the program to error.I use appsrc name=raw_src is-live=true do-timestamp=true format=3! nvjpegenc ! Is appsink name=jpg_sink max-buffers=1 drop=true correct? Or some other problem,thank you.

Hi,
We would suggest use test-launch to run a RTSP server. You may check the steps in
Jetson Nano FAQ

Q: Is there any example of running RTSP streaming?

We don’t have much experience in RTMP. You may refer to
Gstreamer issue with adding timeoverlay on RTMP stream

For this error:

JPEG parameter struct mismatch: library thinks size is 584, caller expects 720

It should be because libjpeg.so is loaded instead of libnvjpeg.so. Please check this.

1 Like

Okay, thank you very much for your valuable answer, I will try to solve it myself first, and then ask you if I encounter something I don’t understand.

Not sure, but you may try to start your app with preloading libgstnvjpeg.so:

LD_PRELOAD=/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvjpeg.so <your_app>

This would allow nvjpeg to run fine, though if your app requires libjpeg you may face a similar (opposite) error.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.