revmischa / rtsp-server

Lightweight RTSP/RTP streaming media server
https://metacpan.org/release/RTSP-Server
427 stars 111 forks source link

Problem with playing the recorded stream #13

Closed orenxperitos closed 7 years ago

orenxperitos commented 7 years ago

Hi revmischa.

I'm trying to broadcast a stream with ffmpeg, and then play it with VlC but without success:

First: I stream to the rtsp-server with this command: ./ffmpeg -re -i "/home/oren/Music/Bar-Yojai.mp3" -f rtsp -muxdelay 0.1 rtsp://127.0.0.1:5545/live.sdp

If i try to play it while the stream is being recorded i get this log:

oren@oren-VirtualBox:~/Sources/rtsp-server-master$ sudo ./rtsp-server.pl -l 4 Starting RTSP server, log level = 4 Source server started Client server started Source connection from 127.0.0.1:46350 Got method OPTIONS Got method ANNOUNCE Got source announcement for rtsp://127.0.0.1:5545/live.sdp Mounted /live.sdp Got method SETUP Got SETUP request for stream 0 Creating new stream 0 Got method RECORD Got record for mountpoint /live.sdp Starting RTP listeners |-- stream 0 |---- port 20000 |---- port 20001 Source connection from 127.0.0.1:46352 Got method OPTIONS Got method DESCRIBE Got method SETUP Got SETUP request for stream 0 SETUP request for /live.sdp/streamid=0, but the mountpoint is in use Returning error 455: Method Not Valid In This State Got EOF on listener


If i understand the message "but the mountpoint is in use" it means i need to wait until the record is finished right ? If so i get then another problem:

oren@oren-VirtualBox:~/Sources/rtsp-server-master$ sudo ./rtsp-server.pl -l 4 Starting RTSP server, log level = 4 Source server started Client server started Source connection from 127.0.0.1:46360 Got method OPTIONS Got method ANNOUNCE Got source announcement for rtsp://127.0.0.1:5545/live.sdp Mounted /live.sdp Got method SETUP Got SETUP request for stream 0 Creating new stream 0 Got method RECORD Got record for mountpoint /live.sdp Starting RTP listeners |-- stream 0 |---- port 20000 |---- port 20001 Got method TEARDOWN Unmounting /live.sdp Shutting down RTP listeners -> port 20000 -> port 20001 Got EOF on listener Source connection from 127.0.0.1:48398 Got method OPTIONS Got method DESCRIBE Returning 404 for rtsp://127.0.0.1:5545/live.sdp Returning error 404: Not Found Got EOF on listener Source connection from 127.0.0.1:48400 Got method OPTIONS Got EOF on listener

The rtsp-server just unmounts the stream immediatly after the record is finished, so then i cannot access it because it is not found !

What did i miss here ?

revmischa commented 7 years ago

I wonder why it's sending TEARDOWN. Are you running ./ffmpeg on the same machine or different VM/machine? Would try running ffmpeg in some sort of verbose mode to maybe figure out why it's ending it early. Maybe it's not streaming in realtime, but rather streaming as fast as it can decode the mp3?

orenxperitos commented 7 years ago

I'm running ffmpeg on the same machine (in 2 terminal tabs)

Here is a log of the ffmpeg it is runned with high verbosity ( -v 4 )

fmpeg version 0.8.15, Copyright (c) 2000-2013 the FFmpeg developers built on Jan 15 2017 20:50:14 with gcc 4.8.4 configuration: libavutil 51. 9. 1 / 51. 9. 1 libavcodec 53. 8. 0 / 53. 8. 0 libavformat 53. 5. 0 / 53. 5. 0 libavdevice 53. 1. 1 / 53. 1. 1 libavfilter 2. 23. 0 / 2. 23. 0 libswscale 2. 0. 0 / 2. 0. 0 [mp3 @ 0x8f78340] max_analyze_duration 5000000 reached at 5015510 [mp3 @ 0x8f78340] Estimating duration from bitrate, this may be inaccurate Input #0, mp3, from '/home/oren/Music/Bar-Yojai.mp3': Metadata: title : Bar-Yojai track : 1 genre : ?????? ?? album : Menagen Meiron album_artist : Chilik Frank disc : 1 artist : ????? ???? TLEN : 127093 Duration: 00:02:07.05, start: 0.000000, bitrate: 192 kb/s Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 192 kb/s Output #0, rtsp, to 'rtsp://127.0.0.1:5545/live.sdp': Metadata: title : Bar-Yojai track : 1 genre : ?????? ?? album : Menagen Meiron album_artist : Chilik Frank disc : 1 artist : ????? ???? TLEN : 127093 encoder : Lavf53.5.0 Stream #0.0: Audio: aac, 44100 Hz, stereo, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0 Press [q] to stop, [?] for help size= -0kB time=00:00:00.67 bitrate= -0.3kbits/s
size= -0kB time=00:00:01.16 bitrate= -0.2kbits/s
these lines continue more and more till end...

revmischa commented 7 years ago

How long does it take to finish? 2:08?

orenxperitos commented 7 years ago

Yes... Moreover, i've managed to set the output format like the input format but it still re-encodes it.

BUT the more INTERESTING this is that ffmpeg rtspenc.c module always sends TEARDOWN at the end of the stream... SO I made a test and removed the TEARDOWN message, but still i get:

SETUP request for /live.sdp/streamid=0, but the mountpoint is in use Returning error 455: Method Not Valid In This State

So which message it should send to stop recording but NOT REMOVE the mountpoint, so i can get to PLAY state ?

revmischa commented 7 years ago

It should send SETUP only once. It sets up the RTP stream with SDP. Then you stream RTP at it until you're done. Then you send TEARDOWN.

orenxperitos commented 7 years ago

OK, so what message the client that wants to view the stream should send ? can you recommned on a working client (instead vlc) ?

revmischa commented 7 years ago

The viewer client should send SETUP then PLAY if I recall correctly. gstreamer is pretty excellent and supports RTSP quite nicely.

orenxperitos commented 7 years ago

Hi there, I've installed gstreamer but the problem continues. It seems the server always refueses to play the stream beacuse "455: Method Not Valid In This State"

How can i resolve this ?

revmischa commented 7 years ago

I'm sure I don't know. Full debug or network traffic logs would be helpful.

orenxperitos commented 7 years ago

OK I've discoverd the problem ! I was requesting the live.sdp from the 5545 port instead from the regular rtsp port, So the client connection was treated as another Source connection and thus didn't allow me to "change the current mount point parameters"....

Thank you very much fro your time & effort, I appriciate it !