5.5 KiB
Sermon Converter
An event-driven Rust service that automatically detects and converts sermon video files for efficient storage and streaming. Uses the shared video_processing
crate for optimal performance.
Features
- Event-driven file detection - No polling, instant response to new files
- AV1 video conversion with Intel QSV hardware acceleration
- Preserves original filenames - Backend handles metadata parsing
- File stability checking - Ensures files are fully written before processing
- Syncthing-aware - Ignores temporary sync files
- Efficient disk space usage with modern compression
- Configurable via environment variables
Prerequisites
- Rust (latest stable version)
- FFmpeg with AV1 support (or configure different codec)
- Intel Media SDK (for QSV acceleration, optional)
- Sufficient disk space for video processing
Installation
- Clone the repository:
git clone <repository-url>
cd sermon-converter
- Build the project:
cargo build --release
Configuration
Create a .env
file based on .env.example
:
cp .env.example .env
nano .env
Required Environment Variables
# Directory paths (REQUIRED)
SERMON_WATCH_PATH=/path/to/watch/sermons
SERMON_OUTPUT_PATH=/path/to/output/sermons
# FFmpeg Configuration
FFMPEG_BINARY=ffmpeg
VIDEO_CODEC=av1_qsv # or libx264, libx265, etc.
HW_ACCEL=qsv # hardware acceleration
HW_DEVICE=qsv=hw
FFMPEG_PRESET=4
VIDEO_BITRATE=6M
MAX_BITRATE=12M
BUFFER_SIZE=24M
AUDIO_CODEC=libopus # or copy, aac, etc.
AUDIO_BITRATE=192k
# File Stability Settings
STABILITY_CHECK_INTERVAL=1 # seconds between stability checks
STABILITY_REQUIRED_CHECKS=30 # consecutive stable checks required
MAX_STABILITY_WAIT_HOURS=0.5 # maximum time to wait for stability
# Directory Settings
CREATE_YEAR_MONTH_DIRS=true # organize by date (unused currently)
PRESERVE_ORIGINAL_FILES=false # delete original after conversion
Usage
Run the service:
cargo run --release
Or run the built binary:
./target/release/sermon_converter
The service will:
- Process any existing MP4 files in the watch directory
- Watch for new files using efficient event-driven detection
- Wait for file stability before processing
- Convert to optimized format with same filename
- Output converted files for backend metadata handling
Expected File Format
Sermon files should follow the naming convention:
Title - Speaker Month Day Year.mp4
Examples:
God's People in the Time of the End - Pastor John Smith December 28 2024.mp4
The Great Hope - Elder Jane Doe January 15 2025.mp4
The backend will parse this format automatically for metadata.
Running as a System Service
Create a systemd service file at /etc/systemd/system/sermon-converter.service
:
[Unit]
Description=Sermon Video Converter Service
After=network.target
[Service]
Type=simple
User=rockvilleav
Group=rockvilleav
ExecStart=/usr/local/bin/sermon_converter
WorkingDirectory=/home/rockvilleav/sermon-converter
# Load environment variables from .env file
EnvironmentFile=/home/rockvilleav/sermon-converter/.env
# System environment variables
Environment=HOME=/home/rockvilleav
Environment=USER=rockvilleav
# Intel Media Stack (if using QSV)
Environment=LIBVA_DRIVER_NAME=iHD
Environment=LIBVA_DRIVERS_PATH=/opt/intel/media/lib64
Environment=LD_LIBRARY_PATH=/opt/intel/media/lib64
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl enable sermon-converter
sudo systemctl start sermon-converter
sudo systemctl status sermon-converter
View logs:
sudo journalctl -u sermon-converter -f
Architecture
This service uses a clean, event-driven architecture:
- Event Detection: Uses
inotify
for instant file detection (no polling) - File Stability: Ensures files are completely written before processing
- Shared Logic: Uses
video_processing
crate for common functionality - Simple Processing: Convert file, keep same name, let backend handle metadata
- Resource Efficient: Only uses CPU/disk when actually processing files
Video Conversion Details
Default settings (configurable via .env):
- Video Codec: AV1 with Intel QSV acceleration
- Audio Codec: Opus (high efficiency)
- Hardware Acceleration: Intel Quick Sync Video
- Video Bitrate: 6Mbps (configurable)
- Audio Bitrate: 192kbps (configurable)
Troubleshooting
Common Issues
Service fails to start:
# Check if .env file exists and has correct paths
ls -la /home/rockvilleav/sermon-converter/.env
# Verify directories exist and are accessible
ls -la /path/to/watch/sermons
ls -la /path/to/output/sermons
FFmpeg errors:
# Test FFmpeg with your codec
ffmpeg -encoders | grep av1
ffmpeg -hwaccels | grep qsv
# Check Intel Media SDK installation
vainfo
Files not being detected:
# Check logs for file events
sudo journalctl -u sermon-converter -f
# Verify file permissions
ls -la /path/to/watch/sermons/
Out of disk space:
# Service checks for 5GB minimum free space
df -h /path/to/output/sermons
Log Analysis
The service provides detailed logging:
INFO
level: Normal operation, file detection, conversion progressWARN
level: Non-fatal issues (low disk space, sync failures)ERROR
level: Conversion failures, configuration errors
License
See LICENSE file for details.
Contributing
Contributions are welcome! This service is part of a larger church media processing system.