Serve Live Stream with FFmpeg Built-in HTTP Server

This article provides a step-by-step guide on how to utilize the built-in HTTP server functionality in FFmpeg to host and serve a live video stream directly from your machine. You will learn the specific FFmpeg command-line syntax required to listen for incoming HTTP connections and stream video content to clients without needing to set up an external web server.

To serve a live stream directly from FFmpeg, you can use the -listen flag combined with the HTTP protocol. This tells FFmpeg to act as an HTTP server and wait for a client to connect before it begins transmitting the media data. The most compatible format for direct HTTP streaming is MPEG-TS.

Here is the standard command to start an HTTP live streaming server using FFmpeg:

ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f mpegts -listen 1 http://0.0.0.0:8080

Command Breakdown

How to Play the Stream

Once you run the command, FFmpeg will pause and wait for a client to request the stream. To play the live stream:

  1. Open a media player that supports network streams, such as VLC Media Player.
  2. Select Open Network Stream (or press Ctrl+N).
  3. Enter the URL: http://localhost:8080 (if playing on the same machine) or http://<your-ip-address>:8080 (if playing from another device on the same network).
  4. Click Play. FFmpeg will immediately begin encoding and streaming the video.

Limitations of the Built-in Server

While highly convenient for testing and local network streaming, the FFmpeg built-in HTTP server is designed to handle only one client connection at a time. If the client disconnects, the FFmpeg process will terminate. For multi-user distribution, you should stream from FFmpeg to a dedicated media server (like Nginx with the RTMP module, SRS, or Nimble Streamer) using RTMP, SRT, or HLS.