Automate Livestream Highlight Extraction with FFmpeg and AI Running on Linux VPS
A detailed guide to automating livestream highlight cutting using FFmpeg and AI on a Linux VPS, running 24/7 to optimize video content.
Image credit: stevepb · Pixabay Content License
Automate Livestream Highlight Extraction with FFmpeg and AI on Linux VPS
In the digital era, creating high-quality video content from livestreams is essential. However, manually cutting highlights is time-consuming and labor-intensive. By combining FFmpeg – a powerful video processing tool – with AI for content analysis, you can automate the entire highlight extraction process on a Linux VPS, running 24/7. This guide walks you through building an automated system on a Linux VPS, leveraging resources efficiently and optimizing costs.
1. Prerequisites
Before starting, ensure you have the following:
- Linux VPS with at least 4GB RAM and 2 CPU cores (recommended: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways).
- FFmpeg installed.
- Python 3.8+ and required libraries:
ffmpeg-python,torch,transformers,pytube(if downloading livestreams). - An AI model for content analysis (e.g., Whisper for speech recognition, Yolo for behavior detection).
- Storage paths for video input and output.
2. Install and Set Up the System
Perform the following steps on your Linux VPS:
2.1. Install FFmpeg
Run the following commands:
sudo apt update
sudo apt install ffmpeg -y
2.2. Install Python and Libraries
sudo apt install python3 python3-pip -y
pip3 install ffmpeg-python torch transformers pytube
2.3. Create Storage Folders
mkdir -p /home/vps/streams /home/vps/highlights
3. Build the Automated Highlight Cutting Script
Follow these steps to create the processing script:
3.1. Download Livestream (if needed)
from pytube import YouTube
import os
def download_stream(url, output_path):
yt = YouTube(url)
stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
stream.download(output_path)
3.2. Analyze Content Using AI
Use Whisper to transcribe speech and identify key moments (e.g., laughter, applause):
from transformers import pipeline
def analyze_audio_with_ai(video_path):
transcription = pipeline("automatic-speech-recognition", model="openai/whisper-base")
result = transcription(video_path)
return result["text"]
3.3. Cut Highlights Based on Analysis
import ffmpeg
def cut_highlights(video_path, output_dir, start_time, end_time):
(
ffmpeg
.input(video_path)
.trim(start=start_time, end=end_time)
.output(f"{output_dir}/highlight_{start_time}.mp4")
.run()
)
4. Run the System in Background
To ensure the system runs 24/7, use systemd or screen:
4.1. Create a systemd Service
# /etc/systemd/system/livestream-highlight.service
[Unit]
Description=Automated Highlight Cutter
After=network.target
[Service]
Type=simple
User=vps
WorkingDirectory=/home/vps
ExecStart=/usr/bin/python3 /home/vps/highlight_cutter.py
Restart=always
[Install]
WantedBy=multi-user.target
4.2. Enable and Start the Service
sudo systemctl daemon-reload
sudo systemctl enable livestream-highlight.service
sudo systemctl start livestream-highlight.service
5. Verify and Troubleshoot
Check system operation with:
# Check service status
sudo systemctl status livestream-highlight.service
# View logs
sudo journalctl -u livestream-highlight.service -f
5.1. Troubleshooting
- FFmpeg not working: Verify FFmpeg installation and required libraries.
- AI model fails to load: Check network connectivity, RAM, and GPU (if applicable).
- Script errors: Review logs and ensure all libraries are correctly installed.
6. Conclusion
Using FFmpeg and AI, you can efficiently automate livestream highlight extraction on a Linux VPS. Running the system in the background ensures continuous content optimization without manual intervention. This solution is ideal for businesses, influencers, or content creators managing large volumes of livestream videos.
References
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
