Python opencv stream rtsp

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

RTSP streaming using GStreamer

prabhakar-sivanesan/OpenCV-rtsp-server

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Php mysql query return error

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

RTSP streaming using GStreamer

Python implementation to stream camera feed from OpenCV videoCapture via RTSP server using GStreamer 1.0.

This implementation has been developed and tested on Ubuntu 16.04 and 18.04. So the installation steps are specific to debian based linux distros.

Step-1 Install GStreamer-1.0 and related plugins

sudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio 

Step-2 Install RTSP server

sudo apt-get install libglib2.0-dev libgstrtspserver-1.0-dev gstreamer1.0-rtsp 

Run stream.py with required arguments to start the rtsp server

python stream.py --device_id 0 --fps 30 --image_width 640 --image_height 480 --port 8554 --stream_uri /video_stream 

You can view the video feed on rtsp://server-ip-address:8554/stream_uri

You can either use any video player which supports rtsp streaming like VLC player or you can use the open-rtsp.py script to view the video feed.

About

RTSP streaming using GStreamer

Источник

Capture RTSP Stream from IP Camera using OpenCV

Capture RTSP Stream from IP Camera using OpenCV

Most of the IP cameras supports Real Time Streaming Protocol (RTSP) to control audio and video streaming. This tutorial provides example how to capture RTSP stream from IP camera using OpenCV and Python.

OpenCV provides the VideoCapture class which allows capturing video from video files, image sequences, webcams, IP cameras, etc. To capture RTSP stream from IP camera, we need to specify RTSP URL as argument. Since RTSP URL is not standardized, different IP camera manufacturers might use different RTSP URLs. Many manufacturers provide RTSP URL on their website or user manual. RTSP URL usually consists of username, password, IP address of the camera, port number (554 is the default RTSP port number), stream name.

Captured frames displayed in the window using imshow function. A window can be closed by pressing the ESC key (represented as ASCII code 27). Reolink E1 Pro camera has been used for testing.

import cv2 import os RTSP_URL = 'rtsp://user:pass@192.168.0.189:554/h264Preview_01_main' os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp' cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG) if not cap.isOpened(): print('Cannot open RTSP stream') exit(-1) while True: _, frame = cap.read() cv2.imshow('RTSP stream', frame) if cv2.waitKey(1) == 27: break cap.release() cv2.destroyAllWindows()
#include #include using namespace cv; int main() < const std::string RTSP_URL = "rtsp://user:pass@192.168.0.189:554/h264Preview_01_main"; #if WIN32 _putenv_s("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp"); #else setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", 1); #endif Mat frame; VideoCapture cap(RTSP_URL, CAP_FFMPEG); if (!cap.isOpened()) < std::cout while (true) < cap >> frame; imshow("RTSP stream", frame); if (waitKey(1) == 27) < break; >> cap.release(); destroyAllWindows(); return 0; >
package app; import org.opencv.core.*; import org.opencv.highgui.HighGui; import org.opencv.videoio.VideoCapture; import org.opencv.videoio.Videoio; public class Main < static < System.loadLibrary(Core.NATIVE_LIBRARY_NAME); >public static void main(String[] args) < String RTSP_URL = "rtsp://user:pass@192.168.0.189:554/h264Preview_01_main"; System.setProperty("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp"); Mat frame = new Mat(); VideoCapture cap = new VideoCapture(RTSP_URL, Videoio.CAP_FFMPEG); if (!cap.isOpened()) < System.out.println("Cannot open RTSP stream"); System.exit(-1); >while (true) < cap.read(frame); HighGui.imshow("RTSP stream", frame); if (HighGui.waitKey(1) == 27) < break; >> cap.release(); HighGui.destroyAllWindows(); System.exit(0); > >

Resize Image using OpenCV

Draw Marker on Image using OpenCV

OpenCV provides various functions for drawing geometric shapes such as line, rectangle, circle, etc. The.

Bilateral Filtering of the Image using OpenCV

The 9 Comments Found

Just in case you need to close the RTSP window by using «X» button, modify the while loop as follows:

while True: _, frame = cap.read() cv2.imshow('RTSP stream', frame) if cv2.waitKey(1) == 27: break if cv2.getWindowProperty('RTSP stream', cv2.WND_PROP_VISIBLE) < 1: break

I was used RTSP url in local it's working fine, but when I use this url in cloud I didn't get the streaming. Finally it's showing streaming is "0". Please help me out from this problem.

Hi,
If you want to remotely access IP camera by using IP address, you should forward ports in router. Check port forwarding settings in router admin panel. Which ports should be forwarded depends on IP camera. Check documentation in manufacturer website. VLC media player can be used on computer to test if IP camera is accessible remotely.

Thank you for this!
For those of you wanting to use this in WSL, I had to change the
os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp'
to
os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;tcp'

Thanks for this! Can you explain this line:
os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp'

It is an optional line that instructs FFmpeg library to use UDP as the transport protocol instead of TCP when capturing video over RTSP. It's done for performance reasons.

There are no official OpenCV bindings for PHP programming language. However, there are third-party OpenCV bindings available for PHP, such as php-opencv. You need to check how it actively maintained and what features are provided.

Источник

OpenCV, Streams and Video Files

Shenzhen, China

Add a file dependencies.txt with all project pip dependencies:

Install all dependencies with:

pip install -r dependencies.txt 

Webcam Capture​

import cv2 webcam = cv2.VideoCapture(0)  while (True):  ret_, frame = webcam.read()  cv2.imshow("webcam", frame) if cv2.waitKey(1) & 0xFF == ord('q'):  webcam.release() break cv2.destroyAllWindows() 

IP Camera Capture​

import cv2 import os RTSP_URL = 'rtsp://admin:instar@192.168.2.19/livestream/13' os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp' # Use tcp instead of udp if stream is unstable cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG)  if not cap.isOpened(): print('Cannot open RTSP stream')  exit(-1)  while True:  success, img = cap.read()  cv2.imshow('RTSP stream', img)  if cv2.waitKey(1) & 0xFF == ord('q'): # Keep running until you press `q`  cap.release() break cv2.destroyAllWindows() 

Video Stream Recording​

import cv2 import os RTSP_URL = 'rtsp://admin:instar@192.168.2.19/livestream/13' os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp' # Use tcp instead of udp if stream is unstable cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG)  if not cap.isOpened(): print('Cannot open RTSP stream')  exit(-1) frame_width = int(cap.get(3)) frame_height = int(cap.get(4)) fps = 15 video_codec = cv2.VideoWriter_fourcc(*'XVID') video_output = cv2.VideoWriter('recording/captured_video.mp4', video_codec, fps, (frame_width, frame_height))  while True:  ret, frame = cap.read()  if ret == True:  video_output.write(frame)  cv2.imshow("Video Recording", frame)  if cv2.waitKey(1) & 0xFF == ord('q'): break  else: break cap.release() video_output.release() cv2.destroyAllWindows() print('Video was saved!') 

Playback Video Files​

import cv2 cap = cv2.VideoCapture("recording/captured_video.mp4")  while (True):  ret, frame = cap.read()  cv2.imshow("Video Recording", frame)  if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() 

Источник

OpenCV and Real time streaming protocol (RTSP)

Hello friends, this tutorial is about RTSP stream basics, how to process it, and obtain frames in Python. In general, OpenCV is used with webcams connected to computers or also embedded inside them. However, for the surveillance purpose, we commonly use IP cameras that generate video streams using RTSP protocol. We can use such IP cameras in projects of video processing, like motion detection, etc. So let’s start by knowing what RTSP is.

RTSP

It is a network control protocol to deliver multimedia content across the desired networks. With TCP, it provides a reliable stream, and its structure is similar to the HTTP. It was designed mainly for entertainment and communications systems to access and control streaming media servers. The clients can issue commands to the media server like play, record, pause, etc. to enable real-time control of the media servers. RTSP allows for video-on-demand solutions.

Lets try to open some rtsp and http links:

  1. “rtsp://freja.hiof.no:1935/rtplive/definst/hessdalen03.stream”
  2. “http://wmccpinetop.axiscam.net/mjpg/video.mjpg”

Here is the code to obtain frames of video from the rtsp link.

 import cv2 # vid = cv2.VideoCapture(0) # For webcam vid = cv2.VideoCapture("http://wmccpinetop.axiscam.net/mjpg/video.mjpg") # For streaming links while True: _,frame = vid.read() print(frame) cv2.imshow('Video Live IP cam',frame) key = cv2.waitKey(1) & 0xFF if key ==ord('q'): break vid.release() cv2.destroyAllWindows() 

The general syntax of rtsp stream for IP cameras are like:

According to your settings, give the parameters in the link and use in your opencv projects.

Experiment of live webcam stream on webcam

Issue this command in Terminal:

ffmpeg -f avfoundation -pix_fmt yuyv422 -video_size 640x480 -framerate 30 -i "0:0" -ac 2 -vf format=yuyv422 -vcodec libx264 -maxrate 2000k -bufsize 2000k -acodec aac -ar 44100 -b:a 128k -f rtp_mpegts rtp://127.0.0.1:9999

In another terminal run this python code

import cv2 # vid = cv2.VideoCapture(0) # For webcam vid = cv2.VideoCapture("rtp://127.0.0.1:9999") # For streaming links while True: rdy,frame = vid.read() print(rdy) try: cv2.imshow('Video Live IP cam',frame) key = cv2.waitKey(1) & 0xFF if key ==ord('q'): break except: pass vid.release() cv2.destroyAllWindows() 

Wait for the frames to get appear (may take up 10 seconds) after some messages!

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

INSTAR IP camera as OpenCV2 Video Source

mpolinowski/opencv-rtsp

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Most of the IP cameras supports Real Time Streaming Protocol (RTSP) to control audio and video streaming. This tutorial provides example how to capture RTSP stream from IP camera using OpenCV and Python. OpenCV provides VideoCapture class which allows to capture video from video files, image sequences, webcams, IP cameras, etc. To capture RTSP stream from IP camera we need to specify RTSP URL as argument.

Please use the following URLs to use your INSTAR camera with third-party software:

  • RTSP Stream 1: rtsp://user:password@192.168.x.x:port/11
  • RTSP Stream 2: rtsp://user:password@192.168.x.x:port/12
  • RTSP Stream 3: rtsp://user:password@192.168.x.x:port/13

User and password are your camera login and the default RTSP port is 554 - e.g.:

rtsp://admin:instar@192.168.1.19:554/12
mkdir ./opencv-rtsp && cd opencv-rtsp python -m venv .env source .env/bin/activate
import cv2 import os RTSP_URL = 'rtsp://admin:instar@192.168.2.117/11' os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp' cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG) if not cap.isOpened(): print('Cannot open RTSP stream') exit(-1) while True: success, img = cap.read() cv2.imshow('RTSP stream', img) if cv2.waitKey(1) & 0xFF == ord('q'): # Keep running until you press `q` break

About

INSTAR IP camera as OpenCV2 Video Source

Источник

Оцените статью