aiortsp icon indicating copy to clipboard operation
aiortsp copied to clipboard

Can not get stream

Open jmdiazlr opened this issue 1 year ago • 1 comments

Thank you for this project.... I am looking at it to pass range header to get recordings. But my first test is not working, I enabled logs, i am pasting here the end of the log where I believe the problem is:

server RTP/RTCP ports: 8000-8001 stream correctly setup: <Response status=200 msg="OK"" headers={'server': 'YGTek RTSP Server 2.0', 'cseq': '4', 'date': 'Thu Nov 14 01:34:53 2024', 'session': '1325738010', 'transport': 'RTP/AVP/UDP;unicast;client_port=49064-49065;server_port=8000-8001;mode="play"'} content-length=0> session id: 1325738010, timeout: 60, keep_alive: 54 sending warmup RTP uplink traffic sending warmup RTCP uplink traffic playing stream... start playing rtsp://192.168.1.72:8554/profile1/ at time now and speed 1...

sending msg: PLAY rtsp://192.168.1.72:8554/profile1/ RTSP/1.0 CSeq: 5 Scale: 1 Range: npt=now- Session: 1325738010 Authorization: Digest username="admin", realm="ygtechnologyshanghai", nonce="6A1652F04F3B35C3", uri="rtsp://192.168.1.72:8554/profile1/", response="06913b7bf32917ecd63b2e31215ffd26" User-Agent: aiortsp/1.4.0

RESPONSE received: <Response status=200 msg="OK"" headers={'server': 'YGTek RTSP Server 2.0', 'cseq': '5', 'date': 'Thu Nov 14 01:34:53 2024', 'range': 'npt=0.000-0.000', 'session': '1325738010'} content-length=0>

response to play: <Response status=200 msg="OK"" headers={'server': 'YGTek RTSP Server 2.0', 'cseq': '5', 'date': 'Thu Nov 14 01:34:53 2024', 'range': 'npt=0.000-0.000', 'session': '1325738010'} content-length=0> no RTP received for 10 seconds: closing connection closed, error: no data stopping session/playback...

sending msg: TEARDOWN rtsp://192.168.1.72:8554/profile1/ RTSP/1.0 CSeq: 6 Session: 1325738010 Authorization: Digest username="admin", realm="ygtechnologyshanghai", nonce="6A1652F04F3B35C3", uri="rtsp://192.168.1.72:8554/profile1/", response="8c31eac6323dd54a55b7ed2603f63195" User-Agent: aiortsp/1.4.0

connection closed, error: RTSP server failed to answer in time connection to RTSP server 192.168.1.72:8554 closed (error: None)

And my program, that is mainly the quick example of your project (the url is good, tested in vlc, ffmpef, etc.):

`import asyncio from aiortsp.rtsp.reader import RTSPReader import logging import sys

root = logging.getLogger() root.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout) root.addHandler(handler)

async def main(): # Open a reader (which means RTSP connection, then media session) async with RTSPReader("rtsp://admin:[email protected]:8554/profile1", log_level=10, run_loop=False) as reader: # Iterate on RTP packets async for pkt in reader.iter_packets(): # print('PKT', pkt.seq, pkt.pt, len(pkt)) pass

asyncio.run(main())`

jmdiazlr avatar Nov 14 '24 01:11 jmdiazlr

Hello!

The RTSPReader (used in the example) is mainly focused on playing live streams; as such the play request is sent with Range: npt=now- header which is probably not what you want here!

What you can try to do is to adapt the RTSPReader toward taking a seek time in parameter (and potentially a speed) which you could inject in the call to await sess.play() ?

Play takes 2 arguments:

    async def play(self, seek=None, speed=1):
        """
        Send a PLAY request
        :param seek: UTC timestamp where to ask to start. By default, uses 'now'.
        :param speed: Replay speed. Could be used for fast forward playing.
        """

With that you can control starting time and playing speed. I didn't test this for quite a while now, but remember managing to retrieve video from Genetec recorder that way. In the end this library is really just a wrapper on RTSP requests, if you know exactly what you want as headers you can tweak many parts.

Please let me know if it works for you, we may consider trying to make playing time and speed as arguments of RTSPReader

RouquinBlanc avatar Nov 14 '24 10:11 RouquinBlanc