Claude
Skills
Sign in
Back

ffmpeg-streaming

Included with Lifetime
$97 forever

Complete live streaming and protocol system for FFmpeg 7.1 LTS and 8.0.1 (latest stable, released 2025-11-20). PROACTIVELY activate for: (1) RTMP streaming to Twitch/YouTube/Facebook, (2) HLS output and adaptive bitrate (ABR), (3) DASH streaming setup, (4) Low-latency streaming (LL-HLS, LL-DASH), (5) SRT protocol configuration, (6) WebRTC/WHIP sub-second latency (FFmpeg 8.0+), (7) Protocol conversion (RTMP to HLS), (8) Multi-destination streaming, (9) nginx-rtmp integration, (10) Docker streaming services. Provides: Platform-specific stream commands, ABR ladder examples, encryption setup, latency optimization, WHIP authentication, production patterns. Ensures: Reliable live streaming with optimal quality and latency.

Ads & Marketing

What this skill does


## CRITICAL GUIDELINES

### Windows File Path Requirements

**MANDATORY: Always Use Backslashes on Windows for File Paths**

When using Edit or Write tools on Windows, you MUST use backslashes (`\`) in file paths, NOT forward slashes (`/`).

---

## Quick Reference

| Protocol | Latency | Output Format | Best For |
|----------|---------|---------------|----------|
| RTMP | 2-5s | `-f flv rtmp://...` | Twitch, YouTube ingest |
| HLS | 10-30s | `-f hls output.m3u8` | Web playback, CDN |
| LL-HLS | 2-5s | `-hls_flags low_latency` | Low-latency web |
| SRT | <1s | `-f mpegts srt://...` | Reliable contribution |
| DASH | 10-30s | `-f dash output.mpd` | ABR streaming |

| Platform | Ingest URL |
|----------|------------|
| Twitch | `rtmp://live.twitch.tv/app/{key}` |
| YouTube | `rtmp://a.rtmp.youtube.com/live2/{key}` |
| Facebook | `rtmps://live-api-s.facebook.com:443/rtmp/{key}` |

## When to Use This Skill

Use for **live streaming workflows**:
- Broadcasting to Twitch, YouTube, Facebook
- Setting up HLS/DASH servers for VOD
- Building ABR encoding ladders
- Low-latency streaming requirements
- Multi-destination restreaming

---

# FFmpeg Streaming Guide (2025)

Complete guide to live streaming with FFmpeg covering RTMP, HLS, DASH, SRT, and WebRTC protocols.

**Current Latest**: FFmpeg 8.0.1 (released 2025-11-20) - Check with `ffmpeg -version`

## Streaming Protocols Overview

### Protocol Comparison (2025)

| Protocol | Latency | Compatibility | Security | Use Case |
|----------|---------|---------------|----------|----------|
| RTMP | 1-5s | Legacy, ingestion | TLS (RTMPS) | Stream ingestion |
| HLS | 6-30s | Universal | AES-128 | CDN delivery |
| DASH | 6-30s | Wide | DRM-ready | ABR streaming |
| LL-HLS | 2-4s | Apple/modern | AES-128 | Low-latency |
| LL-DASH | 2-4s | Modern browsers | DRM-ready | Low-latency |
| SRT | <1s | Growing | AES-128/256 | Contribution |
| WebRTC | <0.5s | Browsers | DTLS/SRTP | Real-time |
| WHIP | <1s | Emerging | TLS | WebRTC ingestion |

### 2025 Trends
- **SRT replacing RTMP** for contribution/ingest
- **LL-HLS** becoming default for Apple ecosystem
- **WHIP** standardizing WebRTC ingestion (FFmpeg 8.0+)
- **QUIC/HTTP3** emerging for lower latency delivery

## RTMP Streaming

### Basic RTMP Stream

```bash
# Stream to RTMP server
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k \
  -c:a aac -b:a 128k \
  -f flv rtmp://server/live/stream_key
```

### Webcam/Screen to RTMP

```bash
# Linux webcam
ffmpeg -f v4l2 -i /dev/video0 \
  -f alsa -i default \
  -c:v libx264 -preset ultrafast -tune zerolatency -b:v 2500k \
  -c:a aac -b:a 128k \
  -f flv rtmp://server/live/stream_key

# macOS webcam
ffmpeg -f avfoundation -framerate 30 -i "0:0" \
  -c:v libx264 -preset ultrafast -tune zerolatency -b:v 2500k \
  -c:a aac -b:a 128k \
  -f flv rtmp://server/live/stream_key

# Windows screen capture
ffmpeg -f gdigrab -framerate 30 -i desktop \
  -c:v libx264 -preset ultrafast -tune zerolatency -b:v 3000k \
  -c:a aac -b:a 128k \
  -f flv rtmp://server/live/stream_key
```

### RTMP with GPU Encoding

```bash
# NVIDIA NVENC
ffmpeg -re -i input.mp4 \
  -c:v h264_nvenc -preset p3 -tune ll -zerolatency 1 -b:v 6000k \
  -c:a aac -b:a 128k \
  -f flv rtmp://server/live/stream_key

# Intel QSV
ffmpeg -re -init_hw_device qsv=hw -filter_hw_device hw \
  -i input.mp4 \
  -c:v h264_qsv -preset fast -b:v 6000k \
  -c:a aac -b:a 128k \
  -f flv rtmp://server/live/stream_key
```

### RTMPS (Encrypted)

```bash
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k \
  -c:a aac -b:a 128k \
  -f flv rtmps://secure-server/live/stream_key
```

### Twitch/YouTube/Facebook

```bash
# Twitch
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 6000k -maxrate 6000k -bufsize 12000k \
  -g 60 -keyint_min 60 \
  -c:a aac -b:a 160k -ar 44100 \
  -f flv rtmp://live.twitch.tv/app/YOUR_STREAM_KEY

# YouTube
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k \
  -g 60 -keyint_min 60 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY

# Facebook
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 4000k -maxrate 4000k -bufsize 8000k \
  -g 60 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv rtmps://live-api-s.facebook.com:443/rtmp/YOUR_STREAM_KEY
```

## HLS Streaming

### Basic HLS Output

```bash
# Create HLS stream
ffmpeg -i input.mp4 \
  -c:v libx264 -c:a aac \
  -hls_time 6 \
  -hls_list_size 0 \
  -hls_segment_filename "segment_%03d.ts" \
  playlist.m3u8
```

### Live HLS Streaming

```bash
# Live HLS with rolling window
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k \
  -c:a aac -b:a 128k \
  -hls_time 4 \
  -hls_list_size 10 \
  -hls_flags delete_segments \
  -hls_segment_filename "live_%03d.ts" \
  live.m3u8
```

### Adaptive Bitrate HLS (ABR)

```bash
# Multi-bitrate HLS
ffmpeg -i input.mp4 \
  -filter_complex "[0:v]split=3[v1][v2][v3]; \
    [v1]scale=1920:1080[v1out]; \
    [v2]scale=1280:720[v2out]; \
    [v3]scale=854:480[v3out]" \
  -map "[v1out]" -c:v:0 libx264 -b:v:0 5000k -maxrate:v:0 5350k -bufsize:v:0 7500k \
  -map "[v2out]" -c:v:1 libx264 -b:v:1 2800k -maxrate:v:1 2996k -bufsize:v:1 4200k \
  -map "[v3out]" -c:v:2 libx264 -b:v:2 1400k -maxrate:v:2 1498k -bufsize:v:2 2100k \
  -map a:0 -c:a:0 aac -b:a:0 192k \
  -map a:0 -c:a:1 aac -b:a:1 128k \
  -map a:0 -c:a:2 aac -b:a:2 96k \
  -f hls \
  -hls_time 6 \
  -hls_list_size 0 \
  -var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2" \
  -master_pl_name master.m3u8 \
  -hls_segment_filename "stream_%v/segment_%03d.ts" \
  stream_%v/playlist.m3u8
```

### HLS with AES Encryption

```bash
# Generate encryption key
openssl rand 16 > enc.key
echo "http://example.com/enc.key" > enc.keyinfo
echo "enc.key" >> enc.keyinfo
openssl rand -hex 16 >> enc.keyinfo

# Encrypted HLS
ffmpeg -i input.mp4 \
  -c:v libx264 -c:a aac \
  -hls_time 6 \
  -hls_key_info_file enc.keyinfo \
  -hls_segment_filename "encrypted_%03d.ts" \
  encrypted.m3u8
```

### Low-Latency HLS (LL-HLS)

```bash
# LL-HLS with partial segments
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -tune zerolatency \
  -c:a aac \
  -hls_time 4 \
  -hls_list_size 6 \
  -hls_flags independent_segments+delete_segments \
  -hls_segment_type fmp4 \
  -hls_fmp4_init_filename init.mp4 \
  -hls_segment_filename "ll_%03d.m4s" \
  ll_playlist.m3u8
```

## DASH Streaming

### Basic DASH Output

```bash
ffmpeg -i input.mp4 \
  -c:v libx264 -c:a aac \
  -f dash \
  -seg_duration 4 \
  -use_timeline 1 \
  -use_template 1 \
  output.mpd
```

### Adaptive DASH

```bash
ffmpeg -i input.mp4 \
  -map 0:v -map 0:v -map 0:v -map 0:a \
  -c:v libx264 -c:a aac \
  -b:v:0 5M -s:v:0 1920x1080 \
  -b:v:1 3M -s:v:1 1280x720 \
  -b:v:2 1M -s:v:2 640x360 \
  -b:a 128k \
  -f dash \
  -seg_duration 4 \
  -adaptation_sets "id=0,streams=v id=1,streams=a" \
  manifest.mpd
```

### Low-Latency DASH (LL-DASH)

```bash
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset ultrafast -tune zerolatency \
  -c:a aac \
  -f dash \
  -seg_duration 1 \
  -frag_duration 0.1 \
  -streaming 1 \
  -ldash 1 \
  -use_timeline 0 \
  -use_template 1 \
  -remove_at_exit 1 \
  -window_size 5 \
  ll_manifest.mpd
```

## SRT Streaming (FFmpeg 4.0+)

### SRT Listener (Server Mode)

```bash
# FFmpeg as SRT server
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k \
  -c:a aac -b:a 128k \
  -f mpegts "srt://0.0.0.0:9000?mode=listener"
```

### SRT Caller (Client Mode)

```bash
# Send to SRT server
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k \
  -c:a aac -b:a 128k \
  -f mpegts "srt://server:9000?mode=caller"
```

### SRT with Encryption

```bash
# AES-128 encrypted SRT
ffmpeg -re -i input.mp4 \
  -c:v libx264 -c:a aac \
  -f mpegts "srt://server:9000?passphrase=mySecretKey123&pbkeylen=16"
```

### Receive SRT Stream

```bash
# Receive and save
ffmpeg -i "srt://0.0.0.0:9000?mode=lis

Related in Ads & Marketing