HLS Video Streaming Platform
Video streaming platform with HLS processing using Java 21, Spring Boot 3, and FFmpeg.
FFmpeg HLS Processing Guide
What is HLS?
HTTP Live Streaming (HLS) is an adaptive bitrate streaming protocol developed by Apple. It breaks video files into small segments and creates a playlist file that allows video players to stream content efficiently.
Why HLS?
Adaptive Streaming: Automatically adjusts quality based on network conditions
Universal Compatibility: Supported by all modern browsers and devices
Efficient Delivery: Segments can be cached and delivered via CDN
Seamless Playback: No buffering interruptions during quality changes
HTTP-based: Works through firewalls and standard web infrastructure
How FFmpeg Processes HLS(without adaptive bit rates)
to convert videos to HLS format:
Adaptive bit rates
For adaptive bitrate streaming with multiple qualities (which we have implemented):
Command Breakdown
Parameter Description
-i "input_video.mp4" Input video file path -codec: copy Copy video/audio streams without re-encoding (faster processing) -start_number 0 Start segment numbering from 0 -hls_time 10 Each segment duration is 10 seconds -hls_list_size 0 Keep all segments in playlist (0 = unlimited) -f hls Output format is HLS "output_playlist.m3u8" Output playlist file nameProcessing Steps
1. Segmentation
FFmpeg splits the input video into 10-second segments:
2. Playlist Creation
Creates an M3U8 playlist file containing:
3. Stream Copy Benefits
Using
-codec: copy means:No Quality Loss: Original video/audio quality preserved
Fast Processing: No re-encoding, just segmentation
Resource Efficient: Minimal CPU usage
Quick Turnaround: Processing completes in seconds vs minutes
File Structure After Processing(without adaptive bit rates)
How Video Players Use HLS
Load Playlist: Player fetches the
.m3u8 fileParse Segments: Reads segment list and durations
Sequential Download: Downloads segments in order
Buffering: Maintains buffer of upcoming segments
Playback: Plays segments seamlessly while downloading next ones
Advantages of This Approach
Speed
No transcoding = faster processing
10-second segments = quick initial load
Compatibility
Works with original video codec
Standard HLS format supported everywhere
Simplicity
Single quality stream (no adaptive bitrate complexity)
Straightforward implementation
Technical Details
Transport Stream (.ts)
Container format for video segments
Designed for streaming applications
Resilient to transmission errors
Self-contained segments
M3U8 Playlist
UTF-8 encoded M3U playlist
Contains metadata and segment information
Updated dynamically for live streams
Static for video-on-demand (VOD)
This approach provides efficient, fast HLS conversion suitable for most video streaming applications.
Prerequisites
Java 21
Maven 3.6+
FFmpeg installed and in PATH
Setup
Clone repository
Install FFmpeg:
Ubuntu:
sudo apt install ffmpegmacOS:
brew install ffmpegWindows: Download from ffmpeg.org and add to PATH
Req. setup of MySQL Db and it's config in application.properties file
Run:
API Endpoints
Upload Video
Stream Video
Returns the main M3U8 playlist file that video players use to initiate streaming. This endpoint sets the correct MIME type (application/vnd.apple.mpegurl) so browsers know how to handle the response.
Segment Streaming Endpoint
This is where the magic happens. The wildcard pattern captures requests for individual video segments (.ts files) and additional playlist files.
1 like · 22 views · Jun 24, 2025
Developed HLS video streaming platform using Java, Spring Boot, and FFmpeg.