File size: 3,564 Bytes
67e6fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# FFmpeg Clip Generation Methods

This document describes the different FFmpeg methods available for generating video clips from detected plays.

## Benchmark Summary

Tested on 20 plays (~3.8 minutes of video) from OSU vs Tennessee 12.21.24:

| Method | Time | Speedup | File Size | Accuracy |
|--------|------|---------|-----------|----------|
| **Parallel Stream Copy** | 0.8s | **77x** | 132 MB | Keyframe-aligned (~1s variance) |
| **Ultrafast Preset** | 15.2s | **4x** | 371 MB | Frame-accurate |
| **Baseline (Re-encode)** | 63.0s | 1x | 161 MB | Frame-accurate |

## Available Methods

### 1. `stream_copy` (Default)

**Command-line:** `--clip-method stream_copy` or omit flag

Uses FFmpeg's stream copy mode (`-c copy`) to extract clips without re-encoding, then concatenates them. Clips are extracted in parallel for maximum speed.

**Pros:**
- Extremely fast (77x faster than re-encoding)
- Smallest file size (preserves original encoding)
- No quality loss

**Cons:**
- Cuts must align to keyframes (typically every 2-5 seconds in broadcast video)
- Each clip may have ~1-2 extra seconds of footage
- Total output may be ~10% longer than expected

**Best for:** Quick turnaround, highlight reels where extra footage is acceptable

### 2. `ultrafast`

**Command-line:** `--clip-method ultrafast`

Re-encodes video using libx264 with the `ultrafast` preset. This is the fastest encoding option while maintaining frame-accurate cuts.

**Pros:**
- Frame-accurate cuts (exact start/end times)
- 4x faster than baseline encoding
- Good balance of speed and accuracy

**Cons:**
- Larger file size (2.3x baseline due to less compression)
- Still slower than stream copy

**Best for:** When frame-accurate cuts are important but speed is still a priority

### 3. `reencode`

**Command-line:** `--clip-method reencode`

Re-encodes video using libx264 with the `fast` preset and CRF 23. This is the original method used in main.py.

**Pros:**
- Frame-accurate cuts
- Best compression ratio (smallest re-encoded file)
- Highest quality per file size

**Cons:**
- Slowest method
- CPU-intensive

**Best for:** Final production output where file size and quality matter most

## Technical Details

### Keyframe Alignment (Stream Copy)

Video files use keyframes (I-frames) as reference points. When using stream copy:
- FFmpeg can only cut cleanly at keyframe boundaries
- Broadcast video typically has keyframes every 2-5 seconds
- The `--padding` already adds 2 seconds before/after each play, so keyframe variance is usually absorbed

### Parallel Processing

The `stream_copy` method uses Python's `concurrent.futures.ThreadPoolExecutor` with 4 workers to extract clips simultaneously, providing additional speedup beyond just avoiding re-encoding.

## Benchmark Details

Full benchmark results are saved in:
- `output/ffmpeg_benchmark/benchmark_results.json`

Individual method outputs for comparison:
- `output/ffmpeg_benchmark/1_baseline_reencode/output.mp4`
- `output/ffmpeg_benchmark/2_stream_copy/output.mp4`
- `output/ffmpeg_benchmark/3_parallel_stream_copy/output.mp4`
- `output/ffmpeg_benchmark/5_ultrafast/output.mp4`

## Usage Examples

```bash
# Default (fastest - parallel stream copy)
python main.py --video "full_videos/game.mp4"

# Explicit stream copy
python main.py --video "full_videos/game.mp4" --clip-method stream_copy

# Frame-accurate with faster encoding
python main.py --video "full_videos/game.mp4" --clip-method ultrafast

# Original method (best compression)
python main.py --video "full_videos/game.mp4" --clip-method reencode
```