bluenviron / gortsplib

RTSP 1.0 client and server library for the Go programming language
MIT License
696 stars 192 forks source link

Example for reading an RTSP stream and republishing all tracks to a server #91

Closed kaiiorg closed 2 years ago

kaiiorg commented 2 years ago

This may be a weird usecase, but I'm trying to use gortsplib to read an RTSP stream from a camera, then publish it to an endpoint configured on rtsp-simple-server. I've attempted to do so myself, but my naive attempt isn't working correctly. See kaiiorg/client-read-publish. For the record, I'm new to Go, so I may have committed some cardinal sin without realizing; sorry for that.

Additional information:

  1. I'm using rtsp-simple-server 0.17.13.
  2. rtsp-simple-server's config is the default provided with the linux binary, but the paths key was modified:
    paths:
    PublishedStream:
    source: publisher
    ExampleStream:
    # Just using rtsp-simple-server for consistency, a realistic usage would be connecting directly to a camera.
    source: rtsp://admin:PASSWORD@192.168.62.197/media/video1
  3. ffplay works when I stream the ExampleStream:
    • ffplay.exe -x 500 -rtsp_transport tcp "rtsp://192.168.62.145:8554/ExampleStream"
    • image
  4. ffplay does not work when I attempt to stream my republished stream:
    • ffplay.exe -x 500 -rtsp_transport tcp "rtsp://192.168.62.145:8554/PublishedStream"
    • image
      1. Setting both rtsp-simple-server and my test program to use TCP as the transport makes no change

Full Usecase

One of the requirements of the program I'm writing is to:

  1. Get request via HTTP or MQTT
  2. Read the stream from the IP camera
    • This may require adding a header to the RTSP request(s) to stream stored files on the camera instead of the live stream. Its weird, I know.
  3. Publish the stream to an instance of rtsp-simple-server. The publish url would be in the HTTP/MQTT message. This issue would handle parts of 2 and 3.
kaiiorg commented 2 years ago

Today, I tried using the unmodified client-publish-h264 example, publishing to rtsp-simple-server, and am getting the same errors and similar image distortion via both ffplay and vlc.

aler9 commented 2 years ago

Hello, this can be done with gortsplib with a little work, but in my opinion a simpler solutions consists in using ffmpeg, that allows to perform this without writing any code:

ffmpeg -re -i rtsp://original-camera -c copy -f rtsp rtsp://rtsp-server
kaiiorg commented 2 years ago

I'll see if I can get that to work, but it might be better for my particular usecase if I don't have any additional binaries or subprocesses to worry about. I don't have a lot of flash space available to me and the third party I'm working with should be given as few components as I can manage.

aler9 commented 2 years ago

A working example that shows how to read and republish tracks has been added here.

kaiiorg commented 2 years ago

Awesome. Thanks!

github-actions[bot] commented 1 year ago

This issue is being locked automatically because it has been closed for more than 6 months. Please open a new issue in case you encounter a similar problem.