Added more finalization logic, improved logging, added tests for nvenc to try and speed up video rendering

This commit is contained in:
Andrew Beveridge committed 2025-07-07 00:58:05 -04:00
1 parent 3b523ec98c
commit a08fa5cc5b
7 files changed
+3932 -245

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
.vscode
*.csv
*.mp3
lyrics_transcriber_local
# lyrics_transcriber_local
# Andrew functional adds
audio/
+210
View File
@@ -0,0 +1,210 @@
# Karaoke Generator Finalization Setup Guide
This guide explains how to configure the Modal web application to work the same way as your local CLI workflow, including YouTube upload, Dropbox sync, Discord notifications, and file organization.
## Overview
The finalization system now supports all the features from your CLI workflow:
- **YouTube Upload**: Automatically upload final videos to YouTube
- **Dropbox Sync**: Organize files in Dropbox with brand codes (NOMAD-XXXX)
- **Discord Notifications**: Send Discord webhook notifications for new uploads
- **Email Drafts**: Create email drafts for client delivery
- **Public Share**: Copy files to public sharing directories
- **Cloud Sync**: Sync public files to Google Drive
## Step 1: Deploy Updated Modal App
First, deploy the updated Modal app with the new finalization features:
```bash
modal deploy app.py
```
## Step 2: Configure Secrets
Set up your Modal secrets with the required environment variables:
```bash
# Update your existing env-vars secret with Discord webhook
modal secret create env-vars \
ADMIN_TOKENS="your-admin-token-here" \
AUTH_SECRET="your-auth-secret" \
AUDIOSHAKE_API_TOKEN="your-audioshake-token" \
GENIUS_API_TOKEN="your-genius-token"
```
## Step 3: Upload Configuration Files
Use the admin API endpoints to upload your configuration files. You'll need your YouTube client secrets, video description template, and email template.
### Upload YouTube Client Secrets
```bash
curl -X POST "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/upload-config-file" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-F "file_type=youtube_secrets" \
-F "config_file=@/path/to/your/youtube-client-secrets.json"
```
### Upload YouTube Description Template
```bash
curl -X POST "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/upload-config-file" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-F "file_type=youtube_description" \
-F "config_file=@/path/to/your/youtube-description.txt"
```
### Upload Email Template
```bash
curl -X POST "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/upload-config-file" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-F "file_type=email_template" \
-F "config_file=@/path/to/your/email-template.txt"
```
## Step 4: Configure rclone
Set up rclone configuration for Dropbox and Google Drive access. First, create your rclone.conf locally:
```bash
# Configure Dropbox remote
rclone config create andrewdropboxfull dropbox
# Configure Google Drive remote
rclone config create googledrive drive
```
Then upload the rclone configuration:
```bash
# Get your rclone config
cat ~/.config/rclone/rclone.conf
# Upload it via the API
curl -X POST "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/rclone-config" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-F "rclone_conf=@~/.config/rclone/rclone.conf"
```
## Step 5: Configure Finalization Settings
Update the finalization configuration to match your CLI workflow:
```bash
curl -X POST "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/config" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"enable_youtube_upload": true,
"enable_discord_notifications": true,
"enable_folder_organisation": true,
"enable_public_share_copy": true,
"enable_rclone_sync": true,
"enable_email_drafts": true,
"brand_prefix": "NOMAD",
"organised_dir": "/output/organized",
"organised_dir_rclone_root": "andrewdropboxfull:Tracks-Organized",
"public_share_dir": "/output/public-share",
"rclone_destination": "googledrive:Nomad Karaoke",
"discord_webhook_url": "https://discord.com/api/webhooks/1313902611421724734/QcQXuvFpa5E3-PA8QXkeG-3mGJVHXXfbbVYWSmT9a7DoSnE-oOXeSWQpMntmIaw9yqPG"
}'
```
## Step 6: Test Configuration
Test that everything is configured correctly:
```bash
curl -X POST "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/test-config" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN"
```
This will return a detailed test report showing which features are working.
## Step 7: View Current Configuration
You can view your current configuration at any time:
```bash
curl -X GET "https://nomadkaraoke--karaoke-generator-webapp-api-endpoint.modal.run/api/admin/finalization/config" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN"
```
## How It Works
Once configured, when jobs reach the finalization phase (Phase 3), the system will:
1. **Generate Final Videos**: Create all video formats (lossless 4K, lossy 4K, 720p)
2. **Create CDG/TXT Packages**: Generate karaoke machine files
3. **Upload to YouTube**: Upload the lossless MKV with your title/thumbnail
4. **Organize Files**: Move files to Dropbox with brand code (e.g., NOMAD-0948)
5. **Copy to Public Share**: Copy files to public sharing structure
6. **Sync to Google Drive**: Sync public files to Google Drive
7. **Send Discord Notification**: Post notification with YouTube link
8. **Create Email Draft**: Generate email draft for client delivery
## Troubleshooting
### YouTube Upload Issues
- Verify your client secrets file is valid JSON
- Check that the Google Cloud project has YouTube API enabled
- Test authentication by checking if tokens exist in `/tmp/`
### rclone Issues
- Test rclone commands manually in Modal: `modal run app.py::test_rclone`
- Verify remote names match exactly (case-sensitive)
- Check OAuth tokens are still valid
### Discord Notifications
- Verify webhook URL format: `https://discord.com/api/webhooks/...`
- Test webhook manually with curl
### File Organization
- Check volume permissions and disk space
- Verify brand prefix format and existing sequence numbers
## API Endpoints Reference
All admin finalization endpoints require admin authentication:
- `GET /api/admin/finalization/config` - View current configuration
- `POST /api/admin/finalization/config` - Update configuration
- `POST /api/admin/finalization/rclone-config` - Update rclone config
- `POST /api/admin/finalization/upload-config-file` - Upload config files
- `POST /api/admin/finalization/test-config` - Test configuration
## Example Configuration Files
### YouTube Description Template
```
Karaoke version of {youtube_url}
📱 Download karaoke files: {dropbox_url}
🎤 More karaoke tracks: https://nomadkaraoke.com
```
### Email Template
```
Hi there!
Your karaoke track is ready!
🎵 YouTube: {youtube_url}
📁 Downloads: {dropbox_url}
Enjoy singing!
```
## Security Notes
- Configuration files are stored in Modal volumes and encrypted at rest
- rclone tokens are stored securely and not exposed in logs
- Admin endpoints require authentication tokens
- YouTube tokens are managed by Google's OAuth flow
## Next Steps
After setup is complete, your Modal karaoke generation will work exactly like your local CLI, automatically uploading to YouTube, organizing in Dropbox, and sending notifications.
+1276 -154
View File
File diff suppressed because it is too large. Load diff
+1237 -35
View File
File diff suppressed because it is too large. Load diff
+49 -1
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🎤 Nomad Karaoke Generator</title>
<title>Nomad Karaoke Generator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
@@ -231,6 +231,9 @@
<button onclick="showCookieManagement()" class="btn btn-primary">
🍪 Manage YouTube Cookies
</button>
<button onclick="showLogLevelSettings()" class="btn btn-primary">
🔍 Log Level Settings
</button>
<button onclick="refreshData()" class="btn btn-primary">
🔄 Refresh Data
</button>
@@ -316,9 +319,54 @@
<button onclick="scrollToBottom()" class="modal-control-btn secondary" title="Scroll to bottom">⬇️</button>
<button onclick="copyLogsToClipboard()" class="modal-control-btn secondary" title="Copy all logs to clipboard">📋 Copy</button>
<button onclick="toggleAutoScroll()" class="modal-control-btn toggle-active" id="auto-scroll-btn" title="Toggle auto-scroll">🔄 Auto</button>
<button onclick="toggleLogAutoRefresh()" class="modal-control-btn toggle-active" id="log-auto-refresh-btn" title="Toggle automatic log refresh">🔄 Refresh</button>
<button onclick="closeLogTailModal()" class="modal-close">✕</button>
</div>
</div>
<!-- Log Filter Bar (Server-side Filtering) -->
<div class="log-filter-bar">
<div class="filter-row">
<div class="filter-group">
<label class="filter-label">🔍 Include:</label>
<input type="text" id="log-include-filter" class="filter-input" placeholder="Include logs containing..." oninput="applyLogFilters()">
</div>
<div class="filter-group">
<label class="filter-label">🚫 Exclude:</label>
<input type="text" id="log-exclude-filter" class="filter-input" placeholder="Exclude logs containing..." oninput="applyLogFilters()">
</div>
<div class="filter-group">
<label class="filter-label">📊 Level:</label>
<select id="log-level-filter" onchange="applyLogFilters()" class="filter-level-select">
<option value="">All Levels</option>
<option value="DEBUG">DEBUG+ (all levels)</option>
<option value="INFO">INFO+ (info, warning, error, critical)</option>
<option value="WARNING">WARNING+ (warning, error, critical)</option>
<option value="ERROR">ERROR+ (error, critical)</option>
<option value="CRITICAL">CRITICAL only</option>
</select>
</div>
<div class="filter-group">
<label class="filter-label">📄 Limit:</label>
<input type="number" id="log-limit-input" class="filter-limit-input" value="1000" min="10" max="10000" step="100" onchange="applyLogFilters()" title="Maximum number of logs to show">
<div class="limit-presets">
<button onclick="setLogLimit(100)" class="limit-preset-btn">100</button>
<button onclick="setLogLimit(1000)" class="limit-preset-btn">1K</button>
<button onclick="setLogLimit(5000)" class="limit-preset-btn">5K</button>
</div>
</div>
<div class="filter-actions">
<button onclick="toggleRegexMode()" class="filter-regex-btn" id="regex-mode-btn" title="Toggle regex mode">.*</button>
<button onclick="refreshLogs()" class="filter-refresh-btn" title="Refresh logs">🔄</button>
<button onclick="clearAllFilters()" class="filter-clear-btn" title="Clear all filters">🗑️</button>
</div>
</div>
<div class="filter-stats-row">
<span class="filter-stats" id="filter-stats">Loading...</span>
</div>
</div>
<div class="modal-body">
<div id="modal-logs" class="modal-logs font-md">
<div class="logs-loading">Starting log tail...</div>
+972 -3
View File
File diff suppressed because it is too large. Load diff
+187 -51
View File
@@ -146,6 +146,10 @@ class KaraokeFinalise:
if self.non_interactive:
self.ffmpeg_base_command += " -y"
# Detect and configure hardware acceleration
self.nvenc_available = self.detect_nvenc_support()
self.configure_hardware_acceleration()
def check_input_files_exist(self, base_name, with_vocals_file, instrumental_audio_file):
self.logger.info(f"Checking required input files exist...")
@@ -292,11 +296,15 @@ class KaraokeFinalise:
self.logger.info(f" Public share copy: {self.public_share_copy_enabled}")
self.logger.info(f" Public share rclone: {self.public_share_rclone_enabled}")
self.prompt_user_confirmation_or_raise_exception(
f"Confirm features enabled log messages above match your expectations for finalisation?",
"Refusing to proceed without user confirmation they're happy with enabled features.",
allow_empty=True,
)
# Skip user confirmation in non-interactive mode for Modal deployment
if not self.non_interactive:
self.prompt_user_confirmation_or_raise_exception(
f"Confirm features enabled log messages above match your expectations for finalisation?",
"Refusing to proceed without user confirmation they're happy with enabled features.",
allow_empty=True,
)
else:
self.logger.info("Non-interactive mode: automatically confirming enabled features")
def authenticate_youtube(self):
"""Authenticate and return a YouTube service object."""
@@ -313,6 +321,9 @@ class KaraokeFinalise:
if credentials and credentials.expired and credentials.refresh_token:
credentials.refresh(Request())
else:
if self.non_interactive:
raise Exception("YouTube authentication required but running in non-interactive mode. Please pre-authenticate or disable YouTube upload.")
flow = InstalledAppFlow.from_client_secrets_file(
self.youtube_client_secrets_file, scopes=["https://www.googleapis.com/auth/youtube"]
)
@@ -631,80 +642,93 @@ class KaraokeFinalise:
return base_name, artist, title
def execute_command(self, command, description):
self.logger.info(description)
if self.dry_run:
self.logger.info(f"DRY RUN: Would run command: {command}")
else:
self.logger.info(f"Running command: {command}")
exit_code = os.system(command)
# Check if command failed (non-zero exit code)
if exit_code != 0:
error_msg = f"Command failed with exit code {exit_code}: {command}"
self.logger.error(error_msg)
raise Exception(error_msg)
"""Legacy method for backwards compatibility - delegates to execute_command_with_fallback"""
# For backwards compatibility, treat as CPU command
self.execute_command_with_fallback(command, command, description)
def remux_with_instrumental(self, with_vocals_file, instrumental_audio, output_file):
"""Remux the video with instrumental audio to create karaoke version"""
# fmt: off
# This operation is primarily I/O bound (remuxing), so hardware acceleration doesn't provide significant benefit
# Keep the existing approach but use the new execute method
ffmpeg_command = (
f'{self.ffmpeg_base_command} -an -i "{with_vocals_file}" '
f'-vn -i "{instrumental_audio}" -c:v copy -c:a pcm_s16le "{output_file}"'
)
# fmt: on
self.execute_command(ffmpeg_command, "Remuxing video with instrumental audio")
def convert_mov_to_mp4(self, input_file, output_file):
"""Convert MOV file to MP4 format"""
# fmt: off
ffmpeg_command = (
"""Convert MOV file to MP4 format with hardware acceleration support"""
# Hardware-accelerated version
gpu_command = (
f'{self.ffmpeg_base_command} {self.hwaccel_decode_flags} -i "{input_file}" '
f'-c:v {self.video_encoder} {self.get_nvenc_quality_settings("high")} -c:a {self.aac_codec} {self.mp4_flags} "{output_file}"'
)
# Software fallback version
cpu_command = (
f'{self.ffmpeg_base_command} -i "{input_file}" '
f'-c:v libx264 -c:a {self.aac_codec} {self.mp4_flags} "{output_file}"'
)
# fmt: on
self.execute_command(ffmpeg_command, "Converting MOV video to MP4")
self.execute_command_with_fallback(gpu_command, cpu_command, "Converting MOV video to MP4")
def encode_lossless_mp4(self, title_mov_file, karaoke_mp4_file, env_mov_input, ffmpeg_filter, output_file):
"""Create the final MP4 with PCM audio (lossless)"""
# fmt: off
ffmpeg_command = (
"""Create the final MP4 with PCM audio (lossless) using hardware acceleration when available"""
# Hardware-accelerated version
gpu_command = (
f"{self.ffmpeg_base_command} {self.hwaccel_decode_flags} -i {title_mov_file} "
f"{self.hwaccel_decode_flags} -i {karaoke_mp4_file} {env_mov_input} "
f'{ffmpeg_filter} -map "[outv]" -map "[outa]" -c:v {self.video_encoder} '
f'{self.get_nvenc_quality_settings("lossless")} -c:a pcm_s16le {self.mp4_flags} "{output_file}"'
)
# Software fallback version
cpu_command = (
f"{self.ffmpeg_base_command} -i {title_mov_file} -i {karaoke_mp4_file} {env_mov_input} "
f'{ffmpeg_filter} -map "[outv]" -map "[outa]" -c:v libx264 -c:a pcm_s16le '
f'{self.mp4_flags} "{output_file}"'
)
# fmt: on
self.execute_command(ffmpeg_command, "Creating MP4 version with PCM audio")
self.execute_command_with_fallback(gpu_command, cpu_command, "Creating MP4 version with PCM audio")
def encode_lossy_mp4(self, input_file, output_file):
"""Create MP4 with AAC audio (lossy, for wider compatibility)"""
# fmt: off
# This is primarily an audio re-encoding operation, video is copied
# Hardware acceleration doesn't provide significant benefit for copy operations
ffmpeg_command = (
f'{self.ffmpeg_base_command} -i "{input_file}" '
f'-c:v copy -c:a {self.aac_codec} -b:a 320k {self.mp4_flags} "{output_file}"'
)
# fmt: on
self.execute_command(ffmpeg_command, "Creating MP4 version with AAC audio")
def encode_lossless_mkv(self, input_file, output_file):
"""Create MKV with FLAC audio (for YouTube)"""
# fmt: off
# This is primarily an audio re-encoding operation, video is copied
# Hardware acceleration doesn't provide significant benefit for copy operations
ffmpeg_command = (
f'{self.ffmpeg_base_command} -i "{input_file}" '
f'-c:v copy -c:a flac "{output_file}"'
)
# fmt: on
self.execute_command(ffmpeg_command, "Creating MKV version with FLAC audio for YouTube")
def encode_720p_version(self, input_file, output_file):
"""Create 720p MP4 with AAC audio (for smaller file size)"""
# fmt: off
ffmpeg_command = (
f'{self.ffmpeg_base_command} -i "{input_file}" '
f'-c:v libx264 -vf "scale=1280:720" -b:v 200k -preset medium -tune animation '
"""Create 720p MP4 with AAC audio (for smaller file size) using hardware acceleration when available"""
# Hardware-accelerated version with GPU scaling and encoding
gpu_command = (
f'{self.ffmpeg_base_command} {self.hwaccel_decode_flags} -i "{input_file}" '
f'-c:v {self.video_encoder} -vf "{self.scale_filter}=1280:720" '
f'{self.get_nvenc_quality_settings("medium")} -b:v 2000k '
f'-c:a {self.aac_codec} -b:a 128k {self.mp4_flags} "{output_file}"'
)
# fmt: on
self.execute_command(ffmpeg_command, "Encoding 720p version of the final video")
# Software fallback version
cpu_command = (
f'{self.ffmpeg_base_command} -i "{input_file}" '
f'-c:v libx264 -vf "scale=1280:720" -b:v 2000k -preset medium -tune animation '
f'-c:a {self.aac_codec} -b:a 128k {self.mp4_flags} "{output_file}"'
)
self.execute_command_with_fallback(gpu_command, cpu_command, "Encoding 720p version of the final video")
def prepare_concat_filter(self, input_files):
"""Prepare the concat filter and additional input for end credits if present"""
@@ -755,17 +779,21 @@ class KaraokeFinalise:
self.encode_lossless_mkv(output_files["final_karaoke_lossless_mp4"], output_files["final_karaoke_lossless_mkv"])
self.encode_720p_version(output_files["final_karaoke_lossless_mp4"], output_files["final_karaoke_lossy_720p_mp4"])
# Prompt user to check final video files before proceeding
self.prompt_user_confirmation_or_raise_exception(
f"Final video files created:\n"
f"- Lossless 4K MP4: {output_files['final_karaoke_lossless_mp4']}\n"
f"- Lossless 4K MKV: {output_files['final_karaoke_lossless_mkv']}\n"
f"- Lossy 4K MP4: {output_files['final_karaoke_lossy_mp4']}\n"
f"- Lossy 720p MP4: {output_files['final_karaoke_lossy_720p_mp4']}\n"
f"Please check them! Proceed?",
"Refusing to proceed without user confirmation they're happy with the Final videos.",
allow_empty=True,
)
# Skip user confirmation in non-interactive mode for Modal deployment
if not self.non_interactive:
# Prompt user to check final video files before proceeding
self.prompt_user_confirmation_or_raise_exception(
f"Final video files created:\n"
f"- Lossless 4K MP4: {output_files['final_karaoke_lossless_mp4']}\n"
f"- Lossless 4K MKV: {output_files['final_karaoke_lossless_mkv']}\n"
f"- Lossy 4K MP4: {output_files['final_karaoke_lossy_mp4']}\n"
f"- Lossy 720p MP4: {output_files['final_karaoke_lossy_720p_mp4']}\n"
f"Please check them! Proceed?",
"Refusing to proceed without user confirmation they're happy with the Final videos.",
allow_empty=True,
)
else:
self.logger.info("Non-interactive mode: automatically confirming final video files")
def create_cdg_zip_file(self, input_files, output_files, artist, title):
self.logger.info(f"Creating CDG and MP3 files, then zipping them...")
@@ -1057,6 +1085,9 @@ class KaraokeFinalise:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
if self.non_interactive:
raise Exception("Gmail authentication required but running in non-interactive mode. Please pre-authenticate or disable email drafts.")
flow = InstalledAppFlow.from_client_secrets_file(
self.youtube_client_secrets_file, ["https://www.googleapis.com/auth/gmail.compose"]
)
@@ -1124,6 +1155,111 @@ class KaraokeFinalise:
self.logger.info("Using built-in aac codec (basic quality)")
return "aac"
def detect_nvenc_support(self):
"""Detect if NVENC hardware encoding is available."""
try:
self.logger.info("Detecting NVENC hardware acceleration support...")
if self.dry_run:
self.logger.info("DRY RUN: Assuming NVENC is available")
return True
# Use subprocess with timeout to prevent hanging
import subprocess
import signal
def timeout_handler(signum, frame):
raise TimeoutError("NVENC detection timed out")
# Test NVENC availability with a minimal encode test
test_cmd = f"{self.ffmpeg_base_command} -f lavfi -i testsrc=duration=1:size=320x240:rate=1 -c:v h264_nvenc -f null -"
# Set a 30-second timeout for NVENC detection
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(30)
try:
result = subprocess.run(test_cmd, shell=True, capture_output=True, text=True, timeout=25)
signal.alarm(0) # Cancel timeout
nvenc_available = result.returncode == 0
if nvenc_available:
self.logger.info("✓ NVENC hardware encoding detected and available")
else:
self.logger.info("✗ NVENC not available, will use software encoding")
self.logger.debug(f"NVENC test stderr: {result.stderr}")
return nvenc_available
except (subprocess.TimeoutExpired, TimeoutError):
signal.alarm(0)
self.logger.warning("NVENC detection timed out, falling back to software encoding")
return False
except Exception as e:
self.logger.warning(f"Failed to detect NVENC support: {e}, falling back to software encoding")
return False
def configure_hardware_acceleration(self):
"""Configure hardware acceleration settings based on detected capabilities."""
if self.nvenc_available:
self.video_encoder = "h264_nvenc"
self.hwaccel_decode_flags = "-hwaccel cuda -hwaccel_output_format cuda"
self.scale_filter = "scale_cuda"
self.logger.info("Configured for NVIDIA hardware acceleration")
else:
self.video_encoder = "libx264"
self.hwaccel_decode_flags = ""
self.scale_filter = "scale"
self.logger.info("Configured for software encoding")
def get_nvenc_quality_settings(self, quality_mode="high"):
"""Get NVENC settings based on quality requirements."""
if quality_mode == "lossless":
return "-preset lossless"
elif quality_mode == "high":
return "-preset p4 -tune hq -cq 18" # High quality
elif quality_mode == "medium":
return "-preset p4 -cq 23" # Balanced quality/speed
elif quality_mode == "fast":
return "-preset p1 -tune ll" # Low latency, faster encoding
else:
return "-preset p4" # Balanced default
def execute_command_with_fallback(self, gpu_command, cpu_command, description):
"""Execute GPU command with automatic fallback to CPU if it fails."""
self.logger.info(f"{description}")
if self.dry_run:
if self.nvenc_available:
self.logger.info(f"DRY RUN: Would run GPU-accelerated command: {gpu_command}")
else:
self.logger.info(f"DRY RUN: Would run CPU command: {cpu_command}")
return
# Try GPU-accelerated command first if available
if self.nvenc_available and gpu_command != cpu_command:
self.logger.debug(f"Attempting hardware-accelerated encoding: {gpu_command}")
exit_code = os.system(gpu_command)
if exit_code == 0:
self.logger.info(f"✓ Hardware acceleration successful")
return
else:
self.logger.warning(f"✗ Hardware acceleration failed (exit code {exit_code}), falling back to software encoding")
# Use CPU command (either as fallback or primary method)
self.logger.debug(f"Running software encoding: {cpu_command}")
exit_code = os.system(cpu_command)
if exit_code != 0:
error_msg = f"Command failed with exit code {exit_code}: {cpu_command}"
self.logger.error(error_msg)
raise Exception(error_msg)
else:
self.logger.info(f"✓ Software encoding successful")
def process(self, replace_existing=False):
if self.dry_run:
self.logger.warning("Dry run enabled. No actions will be performed.")