warren-bank / node-rtsp-relay

Node.js server to relay RTSP video stream from 'producer' to 'consumer' client endpoint.
GNU General Public License v2.0
4 stars 2 forks source link

Examples #1

Closed nerkn closed 1 year ago

nerkn commented 3 years ago

I had a little trouble sending from ffmpeg and reading from vlc.

For ffmpeg I made this command, I suggest you to add as example, since path is important

ffmpeg -re -f alsa -ac 2 -i hw:0 -f v4l2 -i /dev/video3 -vcodec libx264 -pix_fmt yuv420p -preset veryfast -f rtsp rtsp://SERVERIP:5554/PATH

But I cant watch from vlc, where I used "rtsp://SERVERIP:6554/robos"

rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:56225 request: OPTIONS +198ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 request: OPTIONS +13s rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 request: DESCRIBE +81ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 request: SETUP +87ms rtsp-relay:2:ClientWrapper 6414420869107103751991741278221246126125243 - constructed +1ms rtsp-relay:2:Mounts 497 rtp ports remaining +4ms rtsp-relay:2:ClientWrapper 6414420869107103751991741278221246126125243 new client 5145105554423064113128248282111512541335 +0ms rtsp-relay:2:Client ::ffff:46.155.146.18:55688 Client set up for path /robos, local ports (1004:1005) remote ports (52054:52055) +1ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 request: SETUP +66ms rtsp-relay:2:Mounts 496 rtp ports remaining +1ms rtsp-relay:2:ClientWrapper 6414420869107103751991741278221246126125243 new client 1149441264972190161742531891966697175 +0ms rtsp-relay:2:Client ::ffff:46.155.146.18:55688 Client set up for path /robos, local ports (1006:1007) remote ports (42586:42587) +1ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 request: PLAY +107ms rtsp-relay:2:ConsumerServer 6414420869107103751991741278221246126125243 calling play +0ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 request: TEARDOWN +11s rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55688 tearing down client +1ms rtsp-relay:2:Mounts 497 rtp ports remaining +1ms rtsp-relay:2:Mounts 498 rtp ports remaining +1ms rtsp-relay:2:ConsumerServer ClientWrapper 6414420869107103751991741278221246126125243 gone +0ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55817 request: OPTIONS +46ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55817 request: DESCRIBE +58ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55817 request: SETUP +131ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55817 - we dont support tcp, sending 504: 'rtsp://77.83.202.39:6554/robos/streamid=0' +1ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55817 request: SETUP +68ms rtsp-relay:2:ConsumerServer ::ffff:46.155.146.18:55817 - we dont support tcp, sending 504: 'rtsp://77.83.202.39:6554/robos/streamid=1' +0ms

node is running under docker where all ports are exposed with " --network host"

warren-bank commented 3 years ago

wow, I must be getting old.. I don't even remember writing this repo.

anyway, I glanced over the README.. and see from the error messages in your log that you're hitting the "limitation" it mentions:

limitations (inherited from rtsp-streaming-server library)

  • doesn't support RTP/RTSP/TCP

You'll want to see whether ffmpeg can stream using the older protocol (using RTP and RTCP ports). If you find the proper CLI incantation to make it all work, it would be great if you could post an update to this issue (for future reference).

Sorry I couldn't be more help.

warren-bank commented 3 years ago

Here's a working example using ffmpeg (for both producer and consumer)..

important: order matters

  1. start the rtsp relay server
     rtsp-relay -pport 5554 -cport 6554 --log 5 >log.txt 2>&1
  2. start the rtsp producer server (connect to relay at port 5554)
     ffmpeg -re -stream_loop -1 -i test.mp4 -f rtsp -rtsp_transport udp rtsp://127.0.0.1:5554/stream1
  3. start the rtsp consumer client (connect to relay at port 6554)
     ffplay -rtsp_transport udp rtsp://127.0.0.1:6554/stream1

where:

update:

warren-bank commented 3 years ago

here is a slightly more polished example :smiley:

warren-bank commented 3 years ago

circling back to your initial comment, try running this for your producer:

ffmpeg -re -f alsa -ac 2 -i hw:0 -f v4l2 -i /dev/video3 -c:v mpeg1video -q 15 -pix_fmt yuv420p -preset veryfast -f rtsp -rtsp_transport udp -muxdelay 0.1 rtsp://SERVERIP:5554/PATH
hnguyen48206 commented 1 year ago

I hope that this message still be able to reach you guys at this moment. I have tried running the setup just as you @warren-bank mentioned above sir but when I start the ffplay command, I encountered disconnection right away. After adding the logs options, this is what happened.

image

Any help would be much appriciated.

warren-bank commented 1 year ago

thoughts/comments:

  1. yet again.. "wow, I must be getting old.. I don't even remember writing this repo."
  2. I just downloaded the zip snapshot for the HEAD of the master branch
  3. everything worked exactly as it should
    • Cyndi Lauper was.. is.. and always will be amazing :smiley:
  4. looking at the screenshot of the log messages in your terminal..
    • it seems that you were trying to bind to port 1008.. but were unable to do so.
    • was this port already in use at the time of your test?
    • update: on linux.. ports < 1024 are protected.. and require root privilege
      • try using a higher port number
hnguyen48206 commented 1 year ago

Thank you for your timely response sir. Yes, based on the console log, seems like something is wrong with the port 1008 which is where I got lost since I do not purposely using that port. And I have aslo checked the opening ports on the server at that moment, then saw no 1008 port at all.

hnguyen48206 commented 1 year ago

And this is the command that I have used to start the server: rtsp-relay -pport 5554 -cport 6554 --log-level 3 I have noticed in your message that you mentioned pulling the project and do npm i which I did not follow. I've just install the package globally as being described in README, may that be the reason?

warren-bank commented 1 year ago

global install is fine.. i was just testing in a disposable directory

very odd.. -cport is the "consumer port".. which your log message indicates is trying to bind to 1008. off-hand.. no idea why this is happening..

warren-bank commented 1 year ago

darnit.. darnit.. ok, I found the problem.. and it's a bug.. completely my fault:

this defaults --rtp-low-port to 1,000.. but the README says that it should default to 10,000

I forgot a zero..

I'll fix it now and push an update to npm. I'll add another quick comment to let you know when you can pull the fix. Thanks for finding this.. and letting me know about it.

hnguyen48206 commented 1 year ago

No problem sir. Just give me a ping when it's possible.

warren-bank commented 1 year ago

ok.. I just pushed v1.0.2 to npm.

please let me know if this fixes the problem.. (it should)

hnguyen48206 commented 1 year ago

@warren-bank awesome as it should be.

Best Regards.