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
docker :nvcr.io/nvidia/l4t-base:r32.4.2
gi :3.26.1
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)
  • omxh264enc and h264enc
  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

  1. omxh264enc and h264enc

using omxh264enc element will cause the stream to blur
using xh264enc element stream is normal ,but four cpu 100%

Hi,
You can set encoder properties to adjust video quality. Please refer to this post:
H264 vs H265 - #4 by DaneLLL

Hello ,
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

Hi,
We have deprecated omx plugins. Please use nvv4l2h264enc plugin.

Thanks for your reminding,but
I’m using

omxh264enc bitrate=12000000 qp-range=34,39:40,45:-1,-1

then resolution the problem

complete command

appsrc is-live=true ! videoconvert !  omxh264enc bitrate=12000000 qp-range=34,39:40,45:-1,-1 ! video/x-h264,  stream-format=byte-stream ! rtph264pay pt=96 ! udpsink host=127.0.0.1 port=8554 async=false

Hi,
We have deprecated omx plugins( omxh264enc, omxh264dec, … ). Please use v4l2 plugin( nvv4l2h264enc, nvv4l2decoder, … ).