HTTP Live Streaming (HLS) Tutorial for Beginners
Step-by-step HLS tutorial covering setup, encoding, segmentation, and delivery. Start streaming with HLS from scratch.
What You'll Need
To set up HLS streaming from scratch, you need:
- A video file to stream (or a live video source)
- FFmpeg for encoding and segmenting
- A web server (Apache, Nginx, or a CDN)
- An HLS-compatible player (like our online player)
Step 1: Encode and Segment Your Video
Use FFmpeg to create an HLS stream from a video file:
ffmpeg -i input.mp4 \ -filter_complex "[0:v]split=3[v1][v2][v3];[v1]scale=640:360[v1out];[v2]scale=1280:720[v2out];[v3]scale=1920:1080[v3out]" \ -map [v1out] -map 0:a -c:v libx264 -c:a aac -b:v:0 800k -b:a 128k -f hls -var_stream_map "v:0,a:0" master.m3u8
This creates three quality levels (360p, 720p, 1080p) packaged as an HLS stream.
Step 2: Serve the Files
Upload the generated M3U8 files and TS segments to your web server. Ensure the server is configured with the correct MIME types:
# Nginx configuration application/vnd.apple.mpegurl m3u8; video/mp2t ts;
Step 3: Test Your Stream
Use our online HLS player to test your stream. Paste the master playlist URL and verify:
- All quality levels load correctly
- Adaptive switching works (use Chrome DevTools to throttle bandwidth)
- The stream plays smoothly without errors
Step 4: Optimize for Production
- Use a CDN for global delivery
- Enable HTTPS for secure streaming
- Add AES-128 encryption for content protection
- Implement LL-HLS for lower latency
- Monitor stream health with analytics
Related Articles
What Is HLS Streaming? A Complete Beginner's Guide
Learn what HLS (HTTP Live Streaming) is, how it works, and why it's the most popular streaming protocol for web video delivery.
How HLS Streaming Works: Protocol Explained in Detail
Deep dive into the HLS protocol. Understand master playlists, media segments, adaptive bitrate, and the complete HLS delivery pipeline.
Adaptive Bitrate Streaming: How It Works and Why It Matters
Learn how adaptive bitrate (ABR) streaming delivers smooth video on any connection. The technology behind quality switching explained simply.