From 3aea9f96873ec2fa1c5a677347b17291aa0195bd Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sun, 17 Mar 2024 15:43:29 -0700 Subject: [PATCH] scripts/libraries: Fix RTSP library to work with VLC. --- .../36-Web-Servers/rtsp_video_server_lan.py | 15 ++++++++++----- .../36-Web-Servers/rtsp_video_server_wlan.py | 15 ++++++++++----- scripts/libraries/rtsp.py | 4 +++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_lan.py b/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_lan.py index 322430a46..89fc80306 100644 --- a/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_lan.py +++ b/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_lan.py @@ -7,7 +7,8 @@ # This example shows off how to stream video over RTSP with your OpenMV Cam. # # You can use a program like VLC to view the video stream by connecting to the -# OpenMV Cam's IP address. +# OpenMV Cam's IP address. However, OpenMV IDE has an FFPLAY based RSTP Viewer built-in which +# you can use by going to Tools->Video Tools->Play RSTP Stream. import network import omv @@ -15,11 +16,15 @@ import rtsp import sensor import time -# RTP MJPEG streaming works using JPEG images produced by the OV2640/OV5640 camera modules. -# Not all programs (e.g. VLC) implement the full JPEG standard for decoding any JPEG image -# in RTP packets. Images JPEG compressed by the OpenMV Cam internally may not display. +# If you are using VLC on linux you may need to install the live555 library for RTSP support to +# work. If you are using Ubuntu then run the following command: +# +# sudo apt-get install livemedia-utils -# FFPLAY will correctly handle JPEGs produced by OpenMV software. +# Regarding latency on programs like VLC, the default is typically set to buffer 1 second of video +# before playback. To reduce this you need to reduce the network caching which can be set using +# "show more options" when you open the network stream in VLC. You can reduce this to like 10ms +# to make the video real-time. sensor.reset() diff --git a/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_wlan.py b/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_wlan.py index f8ba3f895..8a56bea07 100644 --- a/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_wlan.py +++ b/scripts/examples/08-RPC-Library/36-Web-Servers/rtsp_video_server_wlan.py @@ -7,7 +7,8 @@ # This example shows off how to stream video over RTSP with your OpenMV Cam. # # You can use a program like VLC to view the video stream by connecting to the -# OpenMV Cam's IP address. +# OpenMV Cam's IP address. However, OpenMV IDE has an FFPLAY based RSTP Viewer built-in which +# you can use by going to Tools->Video Tools->Play RSTP Stream. import network import omv @@ -15,11 +16,15 @@ import rtsp import sensor import time -# RTP MJPEG streaming works using JPEG images produced by the OV2640/OV5640 camera modules. -# Not all programs (e.g. VLC) implement the full JPEG standard for decoding any JPEG image -# in RTP packets. Images JPEG compressed by the OpenMV Cam internally may not display. +# If you are using VLC on linux you may need to install the live555 library for RTSP support to +# work. If you are using Ubuntu then run the following command: +# +# sudo apt-get install livemedia-utils -# FFPLAY will correctly handle JPEGs produced by OpenMV software. +# Regarding latency on programs like VLC, the default is typically set to buffer 1 second of video +# before playback. To reduce this you need to reduce the network caching which can be set using +# "show more options" when you open the network stream in VLC. You can reduce this to like 10ms +# to make the video real-time. sensor.reset() diff --git a/scripts/libraries/rtsp.py b/scripts/libraries/rtsp.py index 016c76311..41cd02873 100644 --- a/scripts/libraries/rtsp.py +++ b/scripts/libraries/rtsp.py @@ -6,6 +6,7 @@ # This work is licensed under the MIT license, see the file LICENSE for details. import errno +import image import random import re import socket @@ -294,7 +295,8 @@ class rtsp_server: self.__close_udp_socket() def __send_rtp(self, image_callback, quality): # private - img = image_callback(self.__pathname, self.__session).to_jpeg(quality=quality) + img = image_callback(self.__pathname, self.__session) + img = img.to_jpeg(quality=quality, subsampling=image.JPEG_SUBSAMPLING_422) if img.width() >= 2040: raise ValueError("Maximum width is 2040") if img.height() >= 2040: