FFMPEG RTSP streaming - ffmpeg

I need help with ffmpeg streaming. I have a Grandstream GSC3510 Speaker that it also works like a telephone. I need to configure a rtsp server for streaming 1 file or mutiple files (if possible) of music. I tried straming with UDP that worked but only RSTP format can be streamed and if a call comes in, interupted while call is in place and then continued when the call is over.
my code for udp worked fine:
ffmpeg -stream_loop -1 -re -i C:\relax.mp3 -vol 30 -filter_complex aresample=16000,asetnsamples=n=160 -acodec g722 -ac 1 -vn -f rtp udp://239.255.255.241:5555
but I cant get RTSP to work Im kind of a new at this so I would really appreciate some help.

Please try the live555 RTSP streaming server to stream the data to grand stream speaker.

Related

Capturing and processing a live RTMP stream

I'm trying to download a live stream (not a file) coming from a live camera feed available at the following website: http://www.dot.ca.gov/video/.
I used Wireshark for sniffing the TCP packets and was able to extract the RTMP parameters, but wasn't able to use them with FFMPEG/VLC for downloading / playing the stream on VLC (I guess I didn't construct the URL correctly).
for example, for the camera feed available here, I got the following parameters:
swfUrl: http://www.dot.ca.gov/research/its/StrobeMediaPlayback.swf
pageUrl: http://www.dot.ca.gov/d4/d4cameras/ct-cam-pop- N17_at_Saratoga_Rd.html
tcUrl: rtmp://wzmedia.dot.ca.gov:1935/D4
Play : E37_at_Lakeville_Rd.stream.
Is there a chance someone is familiar with this and can help with understanding how I can use the above for downloading the stream?
Thanks a lot! Yaniv
ffmpeg -re -i "rtmp://wzmedia.dot.ca.gov:1935/D4" -acodec copy -vcodec libx264 -f flv -y ~/save_stream.flv
"-i " means infile and "-y" means overwrite output files.
you can use ffmpeg -h to see it.

FFMPEG: rtsp stream to a udp stream

I am looking for advice on using ffmpeg to convert RTSP stream to udp stream. What would be the simplest general command to do so? This is what I have right now:
ffmpeg -i rtsp://192.168.1.247/play1.sdp -f mpegts -vcodec mpeg4 -acodec mp2 udp://127.0.0.1:1234
The error I'm getting:
UDP timeout, retrying TCP
method PAUSE failed: 405 PAUSE
rtsp://192....: operation not permitted
Finishing stream 0:0 without any data written to it.
I'm running ubuntu 14.04. Thank you!
Looks like the ffmpeg command you are using good enough. I suspect your RTSP input stream is not valid. Have you verified it? You can do so using below command or in vlc also:
ffplay -i rtsp://192.168.1.247:port/filename
One change in the command could be instead of play1.sdp, you can directly give the stream filename i.e, a playable stream than sdp file. Hope it helps.

Seek and pause video stream from ffserver

I managed to successfully feed ffserver from ffmpeg. ffmpeg takes input as PIPE:
ffmpeg -loglevel fatal -f image2pipe -re -vcodec png -i - -vcodec libx264 http://localhost:8090/%s.ffm
External java process generates svg/png images and pushes to ffpmepg
My ffserver config allows me to buffer live feeds in ffm file without defining the size of the file.
My stream configuration looks like this:
<Stream live2.mjpg>
Feed feed2.ffm
Format mpjpeg
VideoFrameRate 25
VideoSize 640x880
VideoQMin 1
VideoQMax 5
NoAudio
Strict -1
</Stream>
The problem is that, despite that I can watch streams in VLC by opening network:
http://0.0.0.0:8090/live2.mjpg
But I can not seek through already buffered movie.
Is there a way to achieve seeking through movie, pausing, and resume playing from "now"? I have tried already rtsp with h264, mpg and sdp but without success:
<Stream test1.mpg/sdp/h264>
Format rtp
Feed feed2.ffm
VideoCodec libx264
VideoSize 640x880
VideoQMin 1
VideoQMax 5
NoAudio
Strict -1
VideoFrameRate 25
</Stream>
Is rtsp solution for this problem, or I need something else?
Can this be achieved from dynamic file since I am using PIPE?
RTSP
RTSP support in ffserver seems a bit sketchy, you could try Darwin Streaming Server or the Live555 media server. The two seem to support some forms of trick-play at least for VOD. Since you're using a pipe this won't probably help.
RTMP
Some RTMP servers/clients support in-buffer seeking (Smart Seeking).
About Smart Seek
Adobe Media Server 3.5.3 and Flash Player 10.1 work together to
support smart seeking in VOD streams and in live streams that have a
buffer. [Source].
ffserver doesn't support RTMP output but you can use your ffmpeg command to push your stream directly to the server:
ffmpeg -re -i <input> -f flv rtmp://...
There's a Nginx RTMP module and a C++ RTMP server although it's not very clear if they support smart seeking. VLC seems to be able to seek a bit while paused and there are usually options to modify the size of the client RTMP buffer.

How can we transcode live rtmp stream to live hls stream using ffmpeg?

I am trying to convert a live rtmp stream to hls stream on real time.
I got some idea after reading
http://sonnati.wordpress.com/2011/08/30/ffmpeg-%E2%80%93-the-swiss-army-knife-of-internet-streaming-%E2%80%93-part-iv/
i am able to convert the live rtmp stream to hls but not at run time. when i run the command and test for any hsl files (.m3u8 and .ts) i am not able to see but when i interrupt the command and check there i get the hls files as required.
I searched on google for solution but not able to get proper answer.
This is a short guide for HLS streaming with any input file or stream:
I am following user1390208's approach, so I use FFMPEG only to produce the rtmp stream which my server then receives to provide HLS. Instead of Unreal/Wowza/Adobe, I use the free server nginx with the rtmp module, which is quite easy to setup. This is how I do it in short: Any input file or stream -> ffmpeg -> rtmp -> nginx server -> HLS -> Client or more detailed:
input video file or stream (http, rtmp, whatever) --> ffmpeg transcodes live to x.264 + aac, outputs to rtmp --> nginx takes the rtmp and serves a HLS to the user (client).
So on the client side you can use VLC or whatever and connect to the .m3u8 file which is provided by nginx.
I followed this setup guide for nginx.
This is my nginx config file.
This is how I use ffmpeg to transcode my input file to rtmp:
ffmpeg -re -i mydirectory/myfile.mkv -c:v libx264 -b:v 5M -pix_fmt yuv420p -c:a:0 libfdk_aac -b:a:0 480k -f flv rtmp://localhost:12345/hls/mystream;
(the .mkv is 1080p with 5.1 sound, depending on your input, you should use lower bitrates!)
Where do you get the rtmp stream from?
A file? Then you can use exactly my approach.
Any server X with a stream Y? Then you have to change the ffmpeg command to:
ffmpeg -re -i rtmp://theServerX/yourStreamY -c:v libx264 -b:v 5M -pix_fmt yuv420p -c:a:0 libfdk_aac -b:a:0 480k -f flv rtmp://localhost:12345/hls/mystream;
or if your rtmp stream is already h.264/aac encoded, you could try to use the copy option in ffmpeg to stream the content directly to nginx.
As you see in my nginx config file:
My rtmp server has an "application" called "hls". That's the part that describes where nginx listens to ffmpeg's rtmp stream and that's why ffmpeg streams to rtmp://localhost:12345/hls/mystream;
My http server has the location /hls. This means in VLC I can connect to http://myServer:80/hls/mystream.m3u8 to access the HLS stream.
Is everything clear? Happy streaming!
Try this RTMP to HLS command line settings:
ffmpeg -v verbose -i rtmp://<host>:<port>/<stream> -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 <pathToFolderYouWantTo>/<streamName>.m3u8
There might be some delay in the HLS feed. However, it'll work.
As an update to this question, I've managed to complete the live transcoding from RTMP to HLS without the use of ffmpeg, how?
Well just by using the exact same nginx config file shared by user3069376 and being very careful about the paths that you are generating the .m3uh manifesto, the hls option within the RTMP module should take care of it.
As for video player the Video.Js worked like a charm o
If you already have the RTMP live stream ready and playing as HLS then you can simply add .m3u8 after the stream name and make RTMP link to http. For example you have RTMP link like this:
rtmp://XY.Y.ZX.Z/hls/chid
You have to just make the url like this:
http://XY.Y.ZX.Z/hls/chid.m3u8
and it will play smoothly in iOS. I have tried following code and it is working fine.
func setPlayer()
{
// RTMP URL rtmp://XY.Y.ZX.Z/hls/chid be transcripted like this http://XY.Y.ZX.Z/hls/chid.m3u8 it will play normally.
let videoURL = URL(string: "http://XY.Y.ZX.Z/hls/chid.m3u8")
let playerItem = AVPlayerItem(url: videoURL!)
let adID = AVMetadataItem.identifier(forKey: "X-TITLE", keySpace: .hlsDateRange)
let metadataCollector = AVPlayerItemMetadataCollector(identifiers: [adID!.rawValue], classifyingLabels: nil)
//metadataCollector.setDelegate(self, queue: DispatchQueue.main)
playerItem.add(metadataCollector)
let player = AVPlayer(playerItem: playerItem)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
self.player = player
player.play()
}
But it will be slow and laggy because of the high resolution video stream upload. If you make the resolution to low when uploading the video stream, it will work smooth in low bandwidth network as well.
Please note: It is not by FFMPEG as we have already RTMP running by
FFMPEG so I did like this.

Wowza error :Failed to play myStream; stream not found.

i am using ffmpeg for encoding a video which will then be restreamed using wowza.i am new to streaming.first i started wowza using command
/etc/init.d/WowzaMediaServer start
after that i start streaming a MP4 file using rtsp protocol.i used the command
ffmpeg -re -i /usr/local/WowzaMediaServer/content/sample.mp4 -acodec libfdk_aac -vcodec libx264 -f rtsp -muxdelay 0.1 rtsp://myuser:mypassword#127.0.0.1:1935/live/myStream.sdp
video start streaming before all of these i changed admin.password and added a username as myuser and password as mypassword when i run above command its streaming but after that they say go to
WowzaMediaServer/examples/LiveVideoStreaming/FlashRTMPPlayer/Player.html
and fill server with rtmp://localhost:1935/live
and Stream field with myStream
when i click on connect its giving me status
"Failed to play myStream; stream not found."
i am following this article http://www.wowza.com/forums/content.php?354-How-to-set-up-live-streaming-using-an-RTSP-RTP-based-encoder
where i am wrong i dont know.i am unable to figure it out. from wowza support team i am not getting satisfactory answers .so someone work on wowza please help me!!why i am not able to connect my video stream to wowza.Please respond stuck badly.
So it appears there are some basic issues with the rtsp from ffmpeg and then no matches to the play request
You have
ffmpeg -re -i /usr/local/WowzaMediaServer/content/sample.mp4 -acodec libfdk_aac -vcodec libx264 -f rtsp -muxdelay 0.1 rtsp://myuser:mypassword#127.0.0.1:1935/live/myStream.sdp
You need to make sure your ffmpeg has libx264 and libfdk_aac plugins available. You should be able to determine this with just
ffmpeg
and it should print out the libraries available.
If you have all the libraries then you are publishing a stream called
myStream.sdp
You then have instructions that say
and fill server with rtmp://localhost:1935/live
and Stream field with myStream
So you should either change your ffmpeg command to
ffmpeg -re -i /usr/local/WowzaMediaServer/content/sample.mp4 -acodec libfdk_aac -vcodec libx264 -f rtsp -muxdelay 0.1 rtsp://myuser:mypassword#127.0.0.1:1935/live/myStream
Note no .sdp in the stream name any more or use a Stream field in the player of
myStream.sdp
When publishing a stream and then attempting to play it back they must match, otherwise you get back Stream Not Found.
One way to successfully do this is to specify only the port number (65000 in this example), making sure it isn't 1935 and server in your ffmpeg command then create a mystream.stream file in your content directory of your Wowza server with ONLY the following line:
udp://0.0.0:65000
Then, in Wowza/conf/startupstreams.xml, add the following:
<!-- Native RTP example (SDP file is myStream.sdp) -->
<StartupStream>
<Application>live/_definst_</Application>
<MediaCasterType>rtp</MediaCasterType>
<StreamName>mystream.stream</StreamName>
</StartupStream>
Restart wowza and ffmpeg and then re-try your url in with the stream name mystream.stream.

Resources