35 lines
1.7 KiB
Markdown
35 lines
1.7 KiB
Markdown
# Video Content Detection + Renaming — Production Script
|
|
|
|
A working YOLO-based pipeline for detecting video content from frames and renaming generically-named recovered video files (FILE000.MOV pattern).
|
|
|
|
## Script
|
|
|
|
Saved at `/tmp/rename_videos.py` and `/tmp/rename_videos2.py` on rayserver.
|
|
|
|
### Workflow
|
|
1. List all files in the target directory starting with "FILE" (generically-named recovered files)
|
|
2. Extract a video frame at 3 seconds using ffmpeg; fall back to 1 second for short clips
|
|
3. Run YOLOv8n on CPU for content detection
|
|
4. Build descriptive filename: `{people_count}_people_{object1}_{object2}.mov`
|
|
5. Handle filename collisions with `_1`, `_2` suffixes
|
|
6. Files with no detections → `scene.mov`
|
|
|
|
### Key design decisions
|
|
- **CPU inference** — Viable for 80-100 files at ~3-5s/file. GPU not needed for this scale
|
|
- **ffmpeg single-frame extraction** — Much faster than processing the entire video
|
|
- **3-second offset** — Early enough to avoid blank intros, late enough to have content
|
|
- **startswith("FILE") guard** — Makes the script idempotent (won't rename already-named files)
|
|
|
|
### Performance reference
|
|
- **80 files**: ~4-6 minutes total (i7-10700K, CPU)
|
|
- **~60 files** get descriptive names, **~20** remain as `scene` (blank/dark)
|
|
|
|
### Full script (80-file version)
|
|
See `/tmp/rename_videos.py` and `/tmp/rename_videos2.py` for the two-phase version that handled 80 files.
|
|
|
|
### Edge cases
|
|
- `.3GP` files are valid video containers — include them
|
|
- Short clips (<3s): ffmpeg clips to available duration, produces a valid frame
|
|
- Broken headers: ffmpeg hangs if file is truncated — always set `timeout=20`
|
|
- Collisions: use `while os.path.exists(dst)` loop with incrementing counter
|