1

Many people were looking for live streaming solution on a web page. I want to share the following knowledge after doing so many researches and having spent so many time.

Run the following command line.

ffmpeg -y -rtsp_transport udp -i "my_rtsp_url" -vcodec libx264 -listen 1 -movflags isml+frag_keyframe -f mp4 http://ip_address:port_nr/test.mp4

Add the following HTML video tag to your web page.

<video controls autoplay>
    <source src="http://ip_address:port_nr/test.mp4" type ="video/mp4">
</video>

Now you can start live-streaming on your web page.

My question:

In general for a video playback, the browser loads the whole video file test.mp4 first and then just starts playing the video.

With the above technique, how can FFMPEG keep pushing video frames to the video source of the HTML without having a complete video file first?

Or

Video source of the HTML keeps pulling frames from the FFMPEG server?

Does anyone know how it works? I am not looking for a streaming solution. I want to understand how these two work together?

O Connor
  • 4,236
  • 15
  • 50
  • 91
  • Have you seen https://stackoverflow.com/questions/1735933/streaming-via-rtsp-or-rtp-in-html5 ? – fvu Apr 29 '22 at 08:09

1 Answers1

0

In general for a video playback, the browser loads the whole video file test.mp4 first and then just starts playing the video.

This is not true. The browser will stream the file from the server and play it. It will often pre-buffer quite a bit though.

With the above technique, how can FFMPEG keep pushing video frames to the video source of the HTML without having a complete video file first?

The browser doesn't know or care that the source video is live. It streams it like it would any other file.

Eventually if the browser isn't playing anything, it will put backpressure on the stream, causing the TCP window to close to zero, causing FFmpeg to buffer the output and put backpressure on the live source, eventually causing everything to fail because buffers will be full. If you're going to go this route, you need to keep the stream moving client-side by letting the browser play it.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • So the browser keeps sending requests to the server for new frames ? – O Connor Jun 08 '22 at 13:43
  • @OConnor No, there is a single request for video and the server keeps sending the video. It's no different than a really large file of indeterminate length. – Brad Jun 09 '22 at 02:11