# Efficient RTSP video decoding 

**URL:** <https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654>\
**Category:** Jetson Nano\
**Created:** [July 8, 2019, 8:02am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654 "2019-07-08T08:02:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravik](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ravik](https://forums.developer.nvidia.com/u/Ravik)\
**Post date:** [July 8, 2019, 8:02am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/1 "2019-07-08T08:02:13Z")

</div>

Our framework requires converting RTSP video to frames and passing them to the local inference server.

I read **omxh264dec** is being deprecated and tried to use **nvv4l2decoder**

P.s is an efficient way of converting image? I want to use very less CPU during the process.

working string

```auto
#gst_str_1 = ("rtspsrc location=rtsp://admin:123456@192.168.10.51/stream0 latency=0 ! rtph265depay ! h265parse ! omxh265dec ! 'video/x-raw(memory:NVMM) , format=(string)RGBA' ! videoconvert ! appsink")

```

Full script

```auto
import cv2
import numpy as np
 
# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
#gst_str_1 = ("rtsp://192.168.10.78/media/live/2/1")

gst_str_1 = ("rtspsrc location=rtsp://admin:123456@192.168.10.51/stream0 latency=0 ! rtph265depay ! h265parse ! nvv4l2decoder ! nvvidconv ! video/x-raw , format=(string)BGRx ! videoconvert ! appsink")

cap = cv2.VideoCapture(gst_str_1, cv2.CAP_GSTREAMER)

# Check if camera opened successfully
if (cap.isOpened()== False): 
  print("Error opening video stream or file")
 
# Read until video is completed
while(cap.isOpened()):
  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:
 
    # Display the resulting frame
    #cv2.imshow('Frame',frame)
 
    # Press Q on keyboard to exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
      break
 
  # Break the loop
  else: 
    break
 
cap.release()
 
cv2.destroyAllWindows()

```

Result

```auto
python camera_1080p_51.py 
Failed to query video capabilities: Inappropriate ioctl for device
Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 279 
NVMEDIA: Reading sys.display-size : status: 6 
NvMMLiteBlockCreate : Block : BlockType = 279

```

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [July 8, 2019, 9:20am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/2 "2019-07-08T09:20:09Z")

</div>

Hi,  
It is a known issue on r32.1:  
[url][https://devtalk.nvidia.com/default/topic/1055288/jetson-nano/can-t-get-accelerated-gstreamer-pipeline-rtspsrc-rtph264depay-h264parse-nvv4l2decoder-to-wo-/post/5349565/#5349565[/url]](https://devtalk.nvidia.com/default/topic/1055288/jetson-nano/can-t-get-accelerated-gstreamer-pipeline-rtspsrc-rtph264depay-h264parse-nvv4l2decoder-to-wo-/post/5349565/#5349565%5B/url%5D)

For running gstreamer with OpenCV, since appsink only accepts CPU buffers, so there is memcpy() to copy video/x-raw(memory:NVMM) to video/x-raw. To reduce CPU loading, suggest you use tegra\_multimedia\_api instead of OpenCV.

The CPU loading of using omxh264enc and nvv4l2decoder is identical.

---

<div class="post-metadata">

**Author:** ![Ravik](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ravik](https://forums.developer.nvidia.com/u/Ravik)\
**Post date:** [July 8, 2019, 9:45am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/3 "2019-07-08T09:45:33Z")

</div>

Can you provide reference code in python?  
[https://docs.nvidia.com/jetson/l4t-multimedia/l4t\_mm\_video\_decode\_cuda.html](https://docs.nvidia.com/jetson/l4t-multimedia/l4t_mm_video_decode_cuda.html)

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [July 9, 2019, 1:34am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/4 "2019-07-09T01:34:55Z")

</div>

Hi,  
tegra\_multimedia\_api samples are in C/C++. Python is not supported.

---

<div class="post-metadata">

**Author:** ![Ravik](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ravik](https://forums.developer.nvidia.com/u/Ravik)\
**Post date:** [July 11, 2019, 5:34am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/5 "2019-07-11T05:34:36Z")

</div>

Then what is the optimal way in python ?

```auto
import cv2
import numpy as np
 
# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
#gst_str_1 = ("rtsp://192.168.10.78/media/live/2/1")

gst_str_1 = ("rtspsrc location=rtsp://admin:123456@192.168.10.51/stream0 latency=0 ! rtph265depay ! h265parse ! nvv4l2decoder ! nvvidconv ! video/x-raw , format=(string)BGRx ! videoconvert ! appsink")

cap = cv2.VideoCapture(gst_str_1, cv2.CAP_GSTREAMER)

# Check if camera opened successfully
if (cap.isOpened()== False): 
  print("Error opening video stream or file")
 
# Read until video is completed
while(cap.isOpened()):
  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:
 
    # Display the resulting frame
    #cv2.imshow('Frame',frame)
 
    # Press Q on keyboard to exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
      break
 
  # Break the loop
  else: 
    break
 
cap.release()
 
cv2.destroyAllWindows()

```

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [July 11, 2019, 6:11am UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/6 "2019-07-11T06:11:21Z")

</div>

Hi,  
For running python + OpenCV, your pipeline is optimal. For leveraging GPU, you may take tegra\_multimedia\_api into consideration.

---

<div class="post-metadata">

**Author:** ![LoveNvidia](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@LoveNvidia](https://forums.developer.nvidia.com/u/LoveNvidia)\
**Post date:** [July 6, 2020, 2:29pm UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/7 "2020-07-06T14:29:12Z")

</div>

@Ravik  
Could you solve the problem with nvv4l2decoder using python+opencv?

---

<div class="post-metadata">

**Author:** ![Ravik](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ravik](https://forums.developer.nvidia.com/u/Ravik)\
**Post date:** [July 6, 2020, 2:35pm UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/8 "2020-07-06T14:35:42Z")

</div>

yeah, we use DeepStream

we also build our our gst-streamer python binding , around 20x faster.

---

<div class="post-metadata">

**Author:** ![LoveNvidia](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@LoveNvidia](https://forums.developer.nvidia.com/u/LoveNvidia)\
**Post date:** [July 6, 2020, 2:46pm UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/9 "2020-07-06T14:46:26Z")

</div>

@Ravik  
**1-** you use this codes? [link](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/tree/master/apps/deepstream-imagedata-multistream)  
**2-** can you share your decoder code?  
**3** - in the [deep-stream-python-apps](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/tree/master/apps/deepstream-imagedata-multistream), in the **deepstream-imagedata-multistream** codes, How I can stop visualization? I want don’t show me any visualization and only do decoder. and I want to use nvv4l2decoder instead of decodebin decoder because i want to use drop-frame-interval option.

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 14, 2021, 10:01pm UTC](https://forums.developer.nvidia.com/t/efficient-rtsp-video-decoding/77654/10 "2021-10-14T22:01:40Z")

</div>

Closed on October 14, 2021, 10:01pm UTC


