marss / aiortsp

An Asyncio-based RTSP library
GNU Lesser General Public License v3.0
45 stars 8 forks source link

RTSP url parsing? #1

Closed tarasivashchuk closed 4 years ago

tarasivashchuk commented 4 years ago

Hi, I am trying to get a media connection setup with RTSPMediaConnection, however, I can't get the connection right.

My URL is in the form rtsp://host:port/path/to/file/mp4:FILE.m4a, but when I try to connect using the host and port section it always fails. And connecting straight to the file stream doesn't work because of the location of the port in the URL.

What should I do, or am I being stupid somewhere? Your help would be greatly appreciated, thank you!

RouquinBlanc commented 4 years ago

would you mind sharing a bit of the code and/or the debug log output? It could be something wrong between your RTSP server and the lib, many servers don't behave the same way and already had to make a few patches for some cameras... I would not be surprise to discover yet another one. it could be the format of the URL as well? Let me know and I will try to help.

RouquinBlanc commented 4 years ago

A quick way to validate if it works properly is to log like this:

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

async def main():
    # Open a reader (which means RTSP connection, then media session)
    async with RTSPReader('rtsp://host:port/path/to/file/mp4:FILE.m4a', log_level=10) as reader:
        # Iterate on RTP packets
        async for pkt in reader.iter_packets():
            print('PKT', pkt.seq, pkt.pt, len(pkt))

logging.basicConfig()
asyncio.run(main())
tarasivashchuk commented 4 years ago

@RouquinBlanc I actually ended finding a way to use an HTTP request to get the data I was trying to scrape - it was a stream, and the RTSP url would have allowed me to simply use the URL to download the file. But I ended figuring out how to access the chunk list and download all the individual little segments of each stream and then basically just iteratively writing them to a file. I appreciate the help though! If you're trying to solve a larger issue I can go back and try to output the issues I was having, let me know, and thanks again!

RouquinBlanc commented 4 years ago

Happy if you found another way! In any case, you would have ended up with the RTP packets, and there you would need to read those, extract whatever format your video was, and save as file... Nothing trivial, and this lib is purely intended for manipulating the RTP stream, which is way lower level... If you want to save RTSP stream to file, you are probably better off with ffmpeg or gstreamer directly!

Let me know in the future if you ever try again to use it, I would be happy to investigate.