Push MPEG-DASH to Linux Web Server Using FFmpeg
This article provides a practical, step-by-step guide on how to use FFmpeg on a Linux environment to encode a live video source and push it as an MPEG-DASH stream to a web server. You will learn the exact FFmpeg command syntax, how to configure web servers like Nginx to receive the stream, and how to handle live playback directory structures.
Understanding the FFmpeg to DASH Workflow
MPEG-DASH (Dynamic Adaptive Streaming over HTTP) works by breaking a
video stream into small, file-based segments and maintaining an XML
manifest file (with a .mpd extension) that lists these
segments. To push this to a remote Linux web server, FFmpeg acts as the
encoder and packager. It captures the input, encodes it, slices it into
segments, and uploads those segments to the web server in real-time,
typically using HTTP POST or PUT requests.
Step 1: Prepare the Web Server to Receive the Stream
Before running the FFmpeg command, your Linux web server must be configured to accept file uploads into a directory accessible by the public.
Configuring Nginx with the WebDAV Module
Standard Nginx cannot accept HTTP POST or PUT requests for static files without a backend or a specific module. The easiest way to enable this is by using the Nginx WebDAV module.
You need to add a location block to your Nginx configuration file
(usually found in /etc/nginx/sites-available/default):
server {
listen 80;
server_name your_server_ip;
location /dash/ {
root /var/www;
# Enable WebDAV methods for FFmpeg uploads
dav_methods PUT DELETE MKCOL COPY MOVE;
# Set appropriate permissions
create_full_put_path on;
dav_access user:rw group:rw all:r;
# Allow large file uploads for video segments
client_max_body_size 50m;
# Enable CORS so web players can access the stream
add_header 'Access-Control-Allow-Origin' '*' always;
}
}
After saving the configuration, create the directory, adjust the ownership so Nginx can write to it, and restart the service:
sudo mkdir -p /var/www/dash
sudo chown -R www-data:www-data /var/www/dash
sudo systemctl restart nginxStep 2: Construct the FFmpeg Command
With the server ready, you can now run FFmpeg on your source Linux
machine. The following command takes a video input (like a live camera
feed, a test pattern, or an existing file), encodes it into H.264 video
and AAC audio, and streams it to the Nginx endpoint using the
-f dash muxer.
ffmpeg -re -i input.mp4 \
-c:v libx264 -b:v 2500k -g 60 -keyint_min 60 -sc_threshold 0 \
-c:a aac -b:a 128k \
-f dash \
-seg_duration 4 \
-window_size 5 \
-extra_window_size 3 \
-remove_at_exit 1 \
-method PUT \
http://your_server_ip/dash/stream.mpdKey Parameters Explained
-re: Forces FFmpeg to read the input at the native frame rate. This is crucial for live streaming simulations from a file.-g 60 -keyint_min 60 -sc_threshold 0: Forces a closed Group of Pictures (GOP) size of 60 frames. If your video is 30 fps, this ensures a keyframe occurs exactly every 2 seconds, which is vital for clean DASH segment cutting.-f dash: Specifies the output format as MPEG-DASH.-seg_duration 4: Sets the target duration for each video segment to 4 seconds.-window_size 5: Keeps only the last 5 segments in the manifest file, preventing the manifest from growing infinitely during a live broadcast.-remove_at_exit 1: Automatically deletes the segments and manifest from the server when you stop the FFmpeg process.-method PUT: Instructs FFmpeg to use HTTP PUT requests to upload the manifest and.m4ssegments to your web server.
Step 3: Verifying and Playing the Stream
Once FFmpeg is running, look inside the /var/www/dash/
directory on your server. You should see stream.mpd and a
continuous cycle of segment files like init-stream-v1.m4s
and chunk-stream-v1-00001.m4s.
To test the live playback, open a DASH-compliant web player (such as
dash.js or Shaka Player) in your browser and point it to your manifest
URL: http://your_server_ip/dash/stream.mpd.