parent
77d9bd5e10
commit
3f5c9ed02d
184
README.md
184
README.md
|
@ -1,29 +1,26 @@
|
||||||
# Sermon Converter
|
# 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.
|
A Rust-based service that automatically monitors a directory for new sermon video files and converts them to an optimized format for streaming.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Event-driven file detection** - No polling, instant response to new files
|
- Automatic detection of new MP4 files in the watch directory
|
||||||
- **AV1 video conversion** with Intel QSV hardware acceleration
|
- Efficient video conversion using FFmpeg
|
||||||
- **Preserves original filenames** - Backend handles metadata parsing
|
- Preserves audio quality while optimizing video for streaming
|
||||||
- **File stability checking** - Ensures files are fully written before processing
|
- Automatic file organization with date-based naming
|
||||||
- **Syncthing-aware** - Ignores temporary sync files
|
- Syncthing-aware (ignores temporary sync files)
|
||||||
- **Efficient disk space usage** with modern compression
|
|
||||||
- **Configurable via environment variables**
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Rust (latest stable version)
|
- Rust (latest stable version)
|
||||||
- FFmpeg with AV1 support (or configure different codec)
|
- FFmpeg installed and available in PATH
|
||||||
- Intel Media SDK (for QSV acceleration, optional)
|
|
||||||
- Sufficient disk space for video processing
|
- Sufficient disk space for video processing
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
```bash
|
```bash
|
||||||
git clone <repository-url>
|
git clone <your-repository-url>
|
||||||
cd sermon-converter
|
cd sermon-converter
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -34,40 +31,15 @@ cargo build --release
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Create a `.env` file based on `.env.example`:
|
The service uses environment variables for configuration:
|
||||||
|
|
||||||
|
- `SERMON_WATCH_PATH`: Directory to monitor for new sermon videos
|
||||||
|
- `SERMON_OUTPUT_PATH`: Directory where converted videos will be saved
|
||||||
|
|
||||||
|
Example:
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
export SERMON_WATCH_PATH="/path/to/watch/directory"
|
||||||
nano .env
|
export SERMON_OUTPUT_PATH="/path/to/output/directory"
|
||||||
```
|
|
||||||
|
|
||||||
### Required Environment Variables
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 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
|
## Usage
|
||||||
|
@ -84,27 +56,12 @@ Or run the built binary:
|
||||||
|
|
||||||
The service will:
|
The service will:
|
||||||
1. Process any existing MP4 files in the watch directory
|
1. Process any existing MP4 files in the watch directory
|
||||||
2. Watch for new files using efficient event-driven detection
|
2. Continue monitoring for new files
|
||||||
3. Wait for file stability before processing
|
3. Automatically convert new MP4 files as they appear
|
||||||
4. Convert to optimized format with same filename
|
|
||||||
5. 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
|
## Running as a System Service
|
||||||
|
|
||||||
Create a systemd service file at `/etc/systemd/system/sermon-converter.service`:
|
To run as a systemd service, create a service file at `/etc/systemd/system/sermon-converter.service`:
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
[Unit]
|
[Unit]
|
||||||
|
@ -113,23 +70,10 @@ After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=rockvilleav
|
User=<your-username>
|
||||||
Group=rockvilleav
|
Environment="SERMON_WATCH_PATH=/path/to/watch/directory"
|
||||||
ExecStart=/usr/local/bin/sermon_converter
|
Environment="SERMON_OUTPUT_PATH=/path/to/output/directory"
|
||||||
WorkingDirectory=/home/rockvilleav/sermon-converter
|
ExecStart=/path/to/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
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
|
|
||||||
|
@ -141,78 +85,30 @@ Enable and start the service:
|
||||||
```bash
|
```bash
|
||||||
sudo systemctl enable sermon-converter
|
sudo systemctl enable sermon-converter
|
||||||
sudo systemctl start sermon-converter
|
sudo systemctl start sermon-converter
|
||||||
sudo systemctl status sermon-converter
|
|
||||||
```
|
```
|
||||||
|
|
||||||
View logs:
|
|
||||||
```bash
|
|
||||||
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
|
## Video Conversion Details
|
||||||
|
|
||||||
Default settings (configurable via .env):
|
The service converts videos using the following FFmpeg settings:
|
||||||
- **Video Codec**: AV1 with Intel QSV acceleration
|
- Video codec: H.264 (libx264)
|
||||||
- **Audio Codec**: Opus (high efficiency)
|
- Audio codec: AAC
|
||||||
- **Hardware Acceleration**: Intel Quick Sync Video
|
- Video preset: medium
|
||||||
- **Video Bitrate**: 6Mbps (configurable)
|
- Constant Rate Factor (CRF): 23
|
||||||
- **Audio Bitrate**: 192kbps (configurable)
|
- Pixel format: yuv420p
|
||||||
|
- Audio bitrate: 128k
|
||||||
|
- Audio sample rate: 44100 Hz
|
||||||
|
|
||||||
|
## File Naming Convention
|
||||||
|
|
||||||
|
Converted files are named based on the original filename's date pattern:
|
||||||
|
- Input: `YYYY-MM-DD_sermon.mp4`
|
||||||
|
- Output: `YYYY-MM-DD_sermon_converted.mp4`
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Common Issues
|
- **FFmpeg not found**: Ensure FFmpeg is installed and in your system PATH
|
||||||
|
- **Permission denied**: Check that the service has read/write permissions for both watch and output directories
|
||||||
**Service fails to start:**
|
- **Files not detected**: Verify the watch directory path and that files are complete before processing
|
||||||
```bash
|
|
||||||
# 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:**
|
|
||||||
```bash
|
|
||||||
# Test FFmpeg with your codec
|
|
||||||
ffmpeg -encoders | grep av1
|
|
||||||
ffmpeg -hwaccels | grep qsv
|
|
||||||
|
|
||||||
# Check Intel Media SDK installation
|
|
||||||
vainfo
|
|
||||||
```
|
|
||||||
|
|
||||||
**Files not being detected:**
|
|
||||||
```bash
|
|
||||||
# Check logs for file events
|
|
||||||
sudo journalctl -u sermon-converter -f
|
|
||||||
|
|
||||||
# Verify file permissions
|
|
||||||
ls -la /path/to/watch/sermons/
|
|
||||||
```
|
|
||||||
|
|
||||||
**Out of disk space:**
|
|
||||||
```bash
|
|
||||||
# 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 progress
|
|
||||||
- `WARN` level: Non-fatal issues (low disk space, sync failures)
|
|
||||||
- `ERROR` level: Conversion failures, configuration errors
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -220,4 +116,4 @@ See LICENSE file for details.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions are welcome! This service is part of a larger church media processing system.
|
Contributions are welcome! Please submit pull requests or issues through the repository.
|
Loading…
Reference in a new issue