Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work RTSP in python

I need to catch RTSP stream from my IP-camera for convert and streaming to site. First I wanted use ffmpeg, but have not found ffmpeg wrappers for python2.7. Who can help me?

like image 522
Dmitry Avatar asked Sep 17 '25 20:09

Dmitry


2 Answers

you don't need wrappers for ffmpeg, you can just execute commands directly from python

import os
os.system("ffmpeg -i rtsp://192.168.1.100/stream -codec copy -f h264 output.mp4 -codec copy -f mpegts udp://127.0.0.1:3000 &")

this captures an rtsp stream from 192.168.1.100/stream (replace this with your camera IP and streaming url, this would be in the camera settings probably on the camera site at 192.168.1.100), outputs it to an mp4 file and re-streams it to a local udp port 3000

need more information to know exactly what you're looking for

like image 173
ierdna Avatar answered Sep 20 '25 10:09

ierdna


Here's a way to capture a single frame from an RTSP stream and save it to disk. You could modify this to save a video stream as well if you wanted:

import ffmpeg

stream = ffmpeg.input("rtsp://<IP or host>:554/", ss=0)
file = stream.output("test.png", vframes=1)
testfile = file.run(capture_stdout=True, capture_stderr=True)
like image 35
eyeareque Avatar answered Sep 20 '25 09:09

eyeareque