Setting up rtsp stream on Windows - ffmpeg

I am trying to set up an rtsp stream that can be accessed from an application. I have been experimenting with ffmpeg to realize that. I have succeded as far as I was able to stream from ffmpeg to ffplay but I could not load the stream in vlc for example. Here are the calls that I did from two different shells on the same machine:
ffmpeg.exe -y -loop 1 -r 24 -i test_1.jpg -vcodec libx264 -tune stillimage -f rtsp rtsp://127.0.0.1:1234/stream.sdp
ffplay.exe -rtsp_flags listen rtsp://127.0.0.1:1234/stream.sdp
Can anybody explain to me what I would have to do to load the stream as a network stream using vlc? Any help is appreciated.

I have done this before and I'm not sure what was wrong with rtsp output of ffmpeg. But what i can say right now is please consider using Live555 library if you have any streaming scenario. cause the ffmpeg code (for rtp muxer) is not good and it is buggy. ffmpeg has another solution for streaming server which is called ffserver which prepare ffmpeg pipe for vlc or another third-party application. and that's bad written and buggy too (libav group -another fork of libav* libraries) never used ffserver code and in not sure if they have any plan to consider ffserver as their solution. they have ffplay(avplay), ffmpeg(avconv) and ffprobe but not ffserver.
If you want to use Live555 which really easy, you have to just go to their website (www.live555.com) download the source code and build MediaServer application (It is in 'MediaServer' folder). if you read the code's documentation, I'm sure you will have not any problem.It's a basic rtsp server to stream any (supported) accessible file on your HDD via rtsp url of your server.
if you have any problem with code just comment here, so I can help you more with live555.

Related

ffmpeg feeding mp4 file to rtsp stream

I am trying to feed a mp4 file from ffmpeg to rtsp stream using the command on centos 7:
from console 1: ffmpeg -i space.mp4 -vcodec libx264 -tune zerolatency -crf 18 http://localhost:8050/feed1.ffm
from console 2: I have started ffserver and it is started listening.
But when i open http://x.x.x.x:8050/feed1.ffm in browser it shows error:
File ??feed1.ffm? not found
My ffserver.conf file is attached
Browser can't play RTSP directly so you need it delivered in a HTML5 format (HLS) that can load inside a VIDEO tag.
You can directly embed the mp4 inside a VIDEO tag if you wish.
FFMPEG needs to publish the video/stream to a streaming server that supports RTSP or the format you decide to publish as.
You can schedule mp4 videos to play as a live stream with this tool https://broadcastlivevideo.com/schedule-video-playlist-as-live-streaming-channel/ , available as free open source WP plugin.

H264/MP4 live stream from ffmpeg does not work in browser

I cannot visualize a H264/MP4 stream generated by ffmpeg in Chrome, IE, Edge. It works only in Firefox.
My testing environment is Windows 10, all updates done, all browsers up to date.
I have a source MJPEG stream, which I need to transcode to H264/MP4 and show it in browser in a HTML5 element.
In order to provide a working example, I use here this MJPEG stream: http://200.36.58.250/mjpg/video.mjpg?resolution=320x240. In my real case I have MJPEG input from different sources like IP cameras.
I use the following command line:
ffmpeg.exe -use_wallclock_as_timestamps 1 -f mjpeg -i "http://200.36.58.250/mjpg/video.mjpg?resolution=320x240" -f mp4 -c:v libx264 -an -preset ultrafast -tune zerolatency -movflags frag_keyframe+empty_moov+faststart -reset_timestamps 1 -vsync 1 -flags global_header -r 15 "tcp://127.0.0.1:5000?listen"
If I try to visualize the output in VLC, I use this link: tcp://127.0.0.1:5000 and it works.
Then I try to visualize the stream in browser, so I put this into a html document:
<video autoplay controls>
<source src="http://127.0.0.1:5000" type="video/mp4">
</video>
If I open the document in Firefox it works just fine.
But it does not work when trying to open in Chrome, IE or Edge. It seems that the browser tries to connect to the TCP server exposed by ffmpeg, but something happens because ffmpeg exits after few seconds.
In ffmpeg console I can see this:
av_interleaved_write_frame(): Unknown error
Error writing trailer of tcp://127.0.0.1:5000?listen: Error number -10053 occurred
If I inspect the video element in Chrome is can see this error:
Failed to load resource: net::ERR_INVALID_HTTP_RESPONSE
As far as I know all these browsers should support H264 encoded streams transported in MP4 containers. If in the element I replace the link http://127.0.0.1:5000 with a local link to a mp4/H264 encoded file, it is played just fine in each browser. The problem seems to be related to live streaming.
Does anyone know why this happens and how it can be solved?
Thank you!
You're just outputting to a TCP socket. That's not HTTP. Browsers speak HTTP... you need to use an HTTP server in this case.

wowza + live + ffmpeg + hls player, how to create the playlist.m3u8?

I'm trying to setup a wowza live test server and then I can play hls from my mobile app. It do work without any problem for vod. I can play it in my app. I can also see the .m3p8 file if I enter this uri in the browser.
I tried to do the same in live mode (my goal is to test some streaming parameters for live streaming). I tried to use ffmpeg to create the live stream:
ffmpeg -re -i "myInputTestVideo.mp4" -vcodec libx264 -vb 150000 -g 60 -vprofile baseline -level 2.1 -acodec aac -ab 64000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -strict experimental -f mpegts udp://127.0.0.1:10000
I created a "source file" and connected it to the "Incoming Streams".
I can see in my application's Monitoring / Network tab that it do getting the data from ffmpeg.
My problem is how to get the playlist.m3p8 file so I can play it from inside my app (hls based)?
Again, for now I need a way to test playing with the streaming settings and in real live I'll have a real live streaming source.
If I understand your issue correctly and since you said that it works for you with a VoD and its own m3u8 uri, you seem to not know how to construct an m3u8 uri for live sources referenced by a stream file (not source file as you incorrectly wrote).
Considering you named your stream file for example udp.stream (that's the file including the udp://127.0.0.1:10000 address), simply point your hls player application to http://{yourwowzaserver}/{yourliveapp}/udp.stream/playlist.m3u8
You could push it to Wowza as rtsp (much better than udp) and then stream it further on to where you want. To push it to Wowza you probably will need to setup a username and password (Server > Source authentication) and then the output stream from ffmpeg can look something like this: rtsp://{user}:{pass}#{yourwowzaserver}/{yourliveapp}/mystream.
In Wowza you will see mystream in Incomming streams. From there you can access it with the classic http(s)://wowzaip:wowzaport/{yourliveapp}/mystream/playlist.m3u8
Anyways, Wowza support both rtsp and udp so you could use directly. If you want transcoding, ffmpeg will be kinder to server resources than Wowza.
Worked:
To change the output of ffmpeg to -f rtsp rtsp://127.0.0.1:1935/my_app/my.stream.stream and use it as the input in wowza.

Using ffserver to do UDP multicast streaming

Here's the deal. I'm working with IPTV hardware and I need to output a bunch of demo streams. These are MPEG2 transport stream that need to be straight up UDP Multicast streams. I have an ffmpeg command that works great:
ffmpeg -re -i /Volumes/Data/DemoVideos/GRAILrpsp.ts -acodec copy -vcodec copy -f mpegts udp://239.192.1.82:12000[ttl=1,buffer_size=2097157]
What I would like to do is convert this into an ffserver config file instead of having to start a whole bunch of ffmpeg streams and then figuring out how to get them to loop. I'm sure I can do it with the right scripting but what a pain, isn't that what ffserver is for? But I can't find any documentation on doing UDP streaming using ffserver. You can set a multicast address and port but it goes to RTP which this hardware isn't designed for. Any help would be greatly appreciated.
At the time of this post, according to the ffserver Documentation it doesn't support MPEG-TS directly in UDP:
ffserver receives prerecorded files or FFM streams from some ffmpeginstance as input, then streams them over RTP/RTSP/HTTP.

Live transcoding and streaming of MP4 works in Android but fails in Flash player with NetStream.Play.FileStructureInvalid error

Recently I had a task to use ffmpeg as a transcoding as well a streaming tool. The task was to convert the file from a given format to MP4 and immediately stream it, by capturing it from stdout. So far so good. The streaming works well with the native player of android tabs as well as the VLC player. The issue is with the flash player. It gives the following error:
NetStream.Play.FileStructureInvalid : Adobe Flash cannot import files that have invalid file structures.
ffmpeg flags used are
$ ffmpeg -loglevel quiet -i somefile.avi -vbsf h264_mp4toannexb -vcodec libx264 \
-acodec aac -f MP4 -movflags frag_keyframe+empty_moov -re - 2>&1
As noted in the docs for -movflags
The mov/mp4/ismv muxer supports fragmentation. Normally, a MOV/MP4 file has all the metadata about all packets stored in one location (written at the end of the file, it can be moved to the start for better playback using the qt-faststart tool). A fragmented file consists of a number of fragments, where packets and metadata about these packets are stored together. Writing a fragmented file has the advantage that the file is decodable even if the writing is interrupted (while a normal MOV/MP4 is undecodable if it is not properly finished), and it requires less memory when writing very long files (since writing normal MOV/MP4 files stores info about every single packet in memory until the file is closed). The downside is that it is less compatible with other applications.
Either switch to a flash player that can handle fragmented MP4 files, or use a different container format that supports streaming better.
Also, -re is an input-only option, so it would make more sense to specify it before the input, instead of before the output.

Resources