dactylroot / rtsp Goto Github PK
View Code? Open in Web Editor NEWRTSP Client for Python
Home Page: https://pypi.org/project/rtsp/
License: MIT License
RTSP Client for Python
Home Page: https://pypi.org/project/rtsp/
License: MIT License
RTSP resource URIs are not parsed properly per urllib
and currently fed directly to OpenCV. Can add some input cleansing around to help make this parameter more robust.
Hello, great library!
I am trying to do two things by using it. The first one, is to set a max-timeout of rtsp.Client read() function. I mean I am trying to make it try until X seconds and assume the stream is down after those X seconds.
The second one, is to detect a wrong stream url. The following snippet is running with a wrong URL and port but still gives "FOUND" output. Shouldn't it return "NOT FOUND"?
import rtsp
try:
client = rtsp.Client(rtsp_server_uri = 'rtsp://DNA:[email protected]:12345', verbose=True)
client.read()
client.close()
print("FOUND")
except:
print("NOT FOUND")
Can't figure out yet how to elegantly import and use README as docstring.
Should also convert README to rst format?
code:
import rtsp
uri = f"rtsp://user:[email protected]:554/live"
with rtsp.Client(rtsp_server_uri=uri) as client:
client.preview()
ERROR:
Assertion fctx->async_lock failed at libavcodec/pthread_frame.c:155
this code is supposed to work for reading multiple frames from one source. why would you release the stream there? that closes the stream and prevents reading any more frames.
someone just showed up in an OpenCV support context and pointed this out.
The async thread locks stream access, so this packages users can't access informative properties e.g.
Can you tell me how to keep the rtsp connection alive,my connection keep dropping after 10-15 seconds consistently
I'm trying to use this module to read RTSP stream, I tried with the exemple in your readme (One-off Retrieval)
and I got this error :
AttributeError: module 'rtsp' has no attribute 'Client'.
Environment:
- Jetson TX2
- Ubuntu 18.04 LTS
- Python 3.6.9
Hi
I did a bit of googling to discover that authenticated RTSP streams can be accessed with a modified url of form
RTSP_URL = f"rtsp://{USERNAME}:{PASSWORD}@192.168.1.221:554/11"
This could be included in your readme or just left here as an issue :-)
how can I get NTP(Absolute TIMESTAMP) information using cv2 video capture
Failing to clear out the OpenCV buffer leads to lag. Want to test and make sure the buffer is getting cleared quickly.
The OpenCV stream is present under Client._stream
but this should be made more transparent.
Given an unknown source framerate and unknown frame processing time for each frame, we want to be able to always grab the most recent frame at the time of a read()
call. In contrast to traditional process-every-frame stream workflows, which opencv-python seems to have been designed around.
Ideally we could follow cap.set(CV_CAP_PROP_BUFFERSIZE,1)
and then always have the most recent frame available. Unfortunately, contrary to this suggestion, we don't appear to be able to set this property in Python:
In : cap.set(cv2.CAP_PROP_BUFFERSIZE,1)
Out: False
It appears everyone tries to manually flush the buffer themselves e.g. 1 2a 2b
As a workaround, I parameterized the buffer skipping rate. So users of this package still have to be conscious of their source framerate and set a flush rate accordingly.
Some options to consider to fix this:
CAP_PROP_BUFFERSIZE
property for OpenCV.Hi
I have an RTSP camera which is secured with a username and password. This causes the connection to fail with the error
Failed to connect to source rtsp://192.168.1.221:554/11.
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-10-8bc6cd52214b> in <module>
----> 1 client.read().show()
~/anaconda3/lib/python3.6/site-packages/rtsp/__init__.py in read(self)
55 def read(self):
56 """ Return most recent frame as Pillow image. Returns None if none have been retrieved. """
---> 57 return self._capture.read()
58
59 def preview(self):
~/anaconda3/lib/python3.6/site-packages/rtsp/cvstream.py in read(self)
149 self._latest = frame
150 self._stream.release()
--> 151 return Image.fromarray(cv2.cvtColor(self._latest, cv2.COLOR_BGR2RGB))
152
153 def preview(self):
error: OpenCV(3.4.2) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'
This issue indicates there is no frame data, which could be caught, and an appropriate exception raised.
Should support log object dependency-injection style. Allow users to pass in a log file in lieu of the verbose
parameter.
objective
write video output using ffmpegcv
steps
pip install -U rtsp ffmpegcv
code
import rtsp
import ffmpegcv
url = 'http://clausenrc5.viewnetcam.com:50003/nphMotionJpeg?Resolution=320x240' # aspect ratio = 4:3
client = rtsp.Client(rtsp_server_uri = url, verbose = False)
output_file = 'rtsp_ffmpegcv_time.mp4'
vidout = ffmpegcv.VideoWriter(output_file, None, pix_fmt = 'bgr24')
i = 0
while i <= 9:
frame = client.read(raw = True)
vidout.write(frame)
i += 1
client.close()
vidout.release()
result
AttributeError Traceback (most recent call last)
[<ipython-input-29-fc5430a80232>](https://localhost:8080/#) in <cell line: 11>()
12 frame = client.read(raw = True)
13
---> 14 vidout.write(frame)
15
16 i += 1
[/usr/local/lib/python3.10/dist-packages/ffmpegcv/ffmpeg_writer.py](https://localhost:8080/#) in write(self, img)
65 height = int(height_15 / 1.5)
66 else:
---> 67 height, width = img.shape[:2]
68 self.width, self.height = width, height
69 self.in_numpy_shape = img.shape
AttributeError: 'NoneType' object has no attribute 'shape'
best regards
Hello, first thanks for your project and effort put on this.
I'm currently developing a script for FacialRecognition and the APIs that I'm using receive the ByteArray of the image capture using RTSP. I'm wonder if you can guide me how can I achieve this. Actually I have noticed that the read()
method return the image in Pillow format, maybe I should touch your code to change this, but can't find where.
Thank you so much.
Make an optional timeout argument that throws an exception if the connection takes too long to complete.
I've just found this package and was running the sample code.
I'm getting "object has no attribute 'save'" although the camera show as connected:
Connected to video source rtsp://xxxx:[email protected]/.
Traceback (most recent call last):
File "d:\Dev\Python\Rtsp2email\rtsp2mail.py", line 9, in
rclient.read().save("./"+ str(datetime.datetime.now()) +".jpg")
^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'save'
In the docs, you say: "v2.0.0 - lightweight native-Python implementation rtsp client functions"
Are you thinking of using asyncio/concurrency to handle concurrent RTSP streams?
I'm experimenting with different ways of listening to dozens of cameras concurrently and was curious what a native Python solution might look like :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.