GStreamer Manually Encode H264 and RTSP Stream with Pipeline

Hello everyone.

I have two different structures. I will explain in below.

First Structure

Application loop:

  1. Get image from camera.
  2. Do image processing.
  3. Write frame into V4L2 device as RGBA format.

GStreamer Pipeline

ā€œv4l2src device=/dev/video1 ! video/x-raw,format=BGRx ! nvvidconv ! nvv4l2h264enc maxperf-enable=1 bitrate=8000000 ! h264parse ! rtph264pay name=pay0 pt=96 config-interval=1 )ā€

This pipeline converts BGRA to YUV, then encode h264, then parse, then stream as rtsp.

This structure works without no problem.

Second Structure

Application loop:

  1. Get image from camera.
  2. Do image processing.
  3. Convert BGRA frame to YUV frame. (works correctly)
  4. Write YUV frame into NVBuffer. (works correctly)
  5. Encode buffered data as H264 with NvVideoEncoder class. (works correctly)
  6. Write encoded bytestream into V4L2 device.

GStreamer Pipeline
ā€œv4l2src device=/dev/video1 ! h264parse ! rtph264pay name=pay0 pt=96 config-interval=1 )ā€

This pipeline takes bytestream, parse, then stream as rtsp.

This structure does not work. When I try to get rtsp stream with cvlc, I get error about h264 decoding.

In addition, when I write bytestream into a file instead of V4L2 device, I can play h264 file without any problem in vlc.

What may cause this problem? Thank you.

Hi,
For streaming, please set the properties: insert-sps-pps and idrinterval=15. There is reference command in the post:
Gstreamer TCPserversink 2-3 seconds latency - #5 by DaneLLL

And not sure how you launch the RTSP server. You may try test-launch. Please refer to
Jetson Nano FAQ
Q: Is there any example of running RTSP streaming?

Hi,

I use gstreamer rtsp server function to create rtsp stream. And it uses pipeline that uses test-launch.

I set the values you told, but nothing changed, can it be about handling bytestream or writing on v4l2 device before parsing it?

Hi,
Would like to know what formats are supported by the camera source. Please execute $ v4l2-ctl --list-formats-ext and share information.

We figured out the problem. Setting config-interval = -1 for h264parse solved the problem.

1 Like

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