Using gstreamer convert image/raw to rtsp in cv2.VideoWriter on python

I want to using gstreamer pipeline to convert image to rtsp ,but i got a low resolution of video streaming , please help me 。

following is the environment and version
gi :3.26.1
docker :nvcr.io/nvidia/l4t-base:r32.4.2
opencv :4.1.1
gstreamer :1.14.5
jetson nano :2G
python :3.6.9

show info list:

  • part 1(udpsink ,problem)
  • part 2 (udpsrc,no problem)
  • comple code
  • print info
  • open streaming in VLC (media player)
  1. part 1(udpsink ,problem)

out_send = cv2.VideoWriter(
‘appsrc is-live=true ! videoconvert ! omxh264enc bitrate=12000000 ! video/x-h264, stream-format=byte-stream ! rtph264pay pt=96 ! udpsink host=127.0.0.1 port=5400 async=false’,
cv2.CAP_GSTREAMER, 0, 25, (1920,1080), True)

  1. part 2 (udpsrc,no problem)

factory.set_launch(“(udpsrc name=pay0 port=5400 buffer-size=524288
caps="application/x-rtp, media=video, clock-rate=90000,
encoding-name=(string)H264, payload=96 ")”)

  1. comple code

#!/usr/bin/env python
import cv2
import gi
gi.require_version(‘Gst’, ‘1.0’)
gi.require_version(‘GstRtspServer’, ‘1.0’)
from gi.repository import GObject, Gst, GstRtspServer

def main():

out_send = cv2.VideoWriter('appsrc is-live=true ! videoconvert ! \
                            omxh264enc bitrate=12000000 ! video/x-h264, \
                            stream-format=byte-stream ! rtph264pay pt=96 ! \
                            udpsink host=127.0.0.1 port=5400 async=false',
                            cv2.CAP_GSTREAMER, 0, 30, (1920,1080), True)


if not out_send.isOpened():
    print('VideoWriter not opened')
    exit(0)

rtsp_port_num = 8554 

server = GstRtspServer.RTSPServer.new()
server.props.service = "%d" % rtsp_port_num
server.attach(None)

factory = GstRtspServer.RTSPMediaFactory.new()
factory.set_launch("(udpsrc name=pay0 port=5400 buffer-size=524288 \
                    caps=\"application/x-rtp, media=video, clock-rate=90000, \
                    encoding-name=(string)H264, payload=96 \")")
                    
factory.set_shared(True)
server.get_mount_points().add_factory("/ds-test", factory)

# output  rtsp info
print("\n *** Launched RTSP Streaming at rtsp://localhost:%d/ds-test ***\n\n" % rtsp_port_num)    

cap = cv2.VideoCapture(0)

while True:
    _, mat = cap.read()
      
    #do someting inference      
    
    out_send.write(mat)
    cv2.waitKey(30) 

if name == ‘main’:
main()

  1. print info

Framerate set to : 25 at NvxVideoEncoderSetParameterNvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4

*** Launched RTSP Streaming at rtsp://localhost:8554/ds-test ***

H264: Profile = 66, Level = 40

  1. open streaming in VLC (media player)

low resolution of video streaming


normal of video streaming

Hi,
There is a sample of saving to MP4:
Displaying to the screen with OpenCV and GStreamer - #9 by DaneLLL

You may give it a try and see if it works. Some users have mentioned it triggers some issue without a space at the end of pipeline, so you may try

"... ! udpsink host=127.0.0.1 port=5400 async=false " (add a space after async=false)

Hello ,I add a space after " … async = false " , but didn’t work
Now i know problem,because The bitrate of video streaming is too low
image

But i set omxh264enc element bitrate to 12000000 ,Didn’t work 。
what should i do

Looks to be duplicate of
Using gstreamer convert image/raw to rtsp in cv2.VideoWriter on python

Ok ,thanks