How to Split and Upload Video in Real-Time Using FFmpeg

This article explains how to split an incoming video stream into small, manageable segments and upload them to a remote server in real-time using FFmpeg. You will learn the exact FFmpeg commands required to chunk video on the fly and transmit those segments instantly to an HTTP server using the built-in HTTP Live Streaming (HLS) publishing features.

The Real-Time Segmentation and Upload Process

To segment and upload video simultaneously, the most efficient method is using FFmpeg’s native HLS (HTTP Live Streaming) muxer. This tool automatically cuts the incoming video into segments (usually .ts files) and generates a playlist (.m3u8 file). By utilizing the HTTP POST or PUT methods built directly into FFmpeg, these files are sent to your destination web server as soon as they are created.

The FFmpeg Command

Run the following command to start the real-time segmenting and uploading process:

ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f hls \
-hls_time 4 \
-hls_list_size 5 \
-hls_flags delete_segments \
-method PUT \
http://yourserver.com/live/stream.m3u8

Parameter Breakdown

Server-Side Requirements

For this setup to work, your receiving server (such as Nginx, Apache, or a Node.js backend) must be configured to accept HTTP PUT or POST requests at the specified directory. Ensure that the server has write permissions enabled for that location so FFmpeg can successfully save the .m3u8 and .ts files as they are uploaded in real-time.