English | 日本語 |
---|
This script takes an MP4 video file and generates multiple HLS (HTTP Live Streaming) video streams at different resolutions and bitrates. It then launches a simple HTTP server to serve the generated content.
The following tools are required to run this script:
bash
(shell)ffmpeg
(for video encoding)python3
(for HTTP server)
Installation example (Ubuntu/Debian):
sudo apt update
sudo apt install ffmpeg python3
./python-hlsserver.bash
./python-hlsserver.bash 8000
Parameter | Description | Default Value |
---|---|---|
INPUT_FILE |
Name of the input video file | test.mp4 |
OUTPUT_DIR |
Directory to save HLS files | input filename + _hls |
PORT |
Port number for the HTTP server | 8080 |
HLS_PREFIX |
Base URL for each stream in the master playlist | http://10.0.0.1:${PORT} |
- Uses the base name of the input file (without extension) to create an output directory.
- If the directory already exists, the script skips re-encoding and serves existing files.
-
Generates HLS streams for the following resolutions and bitrates:
- 1280x720 (3000 kbps)
- 854x480 (1500 kbps)
- 640x360 (800 kbps)
- 426x240 (400 kbps)
-
Each stream is encoded using
ffmpeg
and saved as.m3u8
and.ts
files in the output directory.
- A master playlist that lists all available stream variants is created.
- Clients can use this playlist to automatically select the appropriate resolution.
- A simple HTTP server is started using Python on the specified port to serve the HLS files.
Access the master playlist at:
http://<server-ip>:<port>/master.m3u8
Example: http://10.0.0.1:8080/master.m3u8