2025-12-07 17:15:09 +02:00
|
|
|
# utils/media.py
|
|
|
|
|
|
|
|
|
|
import subprocess
|
feat: Implement comprehensive non-hierarchical logging system
- Created new logging infrastructure with per-component filtering
- Added 6 log levels: DEBUG, INFO, API, WARNING, ERROR, CRITICAL
- Implemented non-hierarchical level control (any combination can be enabled)
- Migrated 917 print() statements across 31 files to structured logging
- Created web UI (system.html) for runtime configuration with dark theme
- Added global level controls to enable/disable levels across all components
- Added timestamp format control (off/time/date/datetime options)
- Implemented log rotation (10MB per file, 5 backups)
- Added API endpoints for dynamic log configuration
- Configured HTTP request logging with filtering via api.requests component
- Intercepted APScheduler logs with proper formatting
- Fixed persistence paths to use /app/memory for Docker volume compatibility
- Fixed checkbox display bug in web UI (enabled_levels now properly shown)
- Changed System Settings button to open in same tab instead of new window
Components: bot, api, api.requests, autonomous, persona, vision, llm,
conversation, mood, dm, scheduled, gpu, media, server, commands,
sentiment, core, apscheduler
All settings persist across container restarts via JSON config.
2026-01-10 20:46:19 +02:00
|
|
|
from utils.logger import get_logger
|
|
|
|
|
|
|
|
|
|
logger = get_logger('media')
|
2025-12-07 17:15:09 +02:00
|
|
|
|
|
|
|
|
async def overlay_username_with_ffmpeg(base_video_path, output_path, username):
|
|
|
|
|
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
|
|
|
|
text = f"@{username}"
|
|
|
|
|
|
|
|
|
|
# Define your six positions (x, y)
|
|
|
|
|
positions = {
|
|
|
|
|
1: ("250", "370"),
|
|
|
|
|
2: ("330", "130"),
|
|
|
|
|
3: ("300", "90"),
|
|
|
|
|
4: ("380", "180"),
|
|
|
|
|
5: ("365", "215"),
|
|
|
|
|
6: ("55", "365"),
|
|
|
|
|
7: ("290", "130"),
|
|
|
|
|
8: ("320", "210"),
|
|
|
|
|
9: ("310", "240"),
|
|
|
|
|
10: ("400", "240")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Each entry: (start_time, end_time, position_index)
|
|
|
|
|
text_entries = [
|
|
|
|
|
(4.767, 5.367, 1, "username"),
|
|
|
|
|
(5.4, 5.967, 2, "username"),
|
|
|
|
|
(6.233, 6.833, 3, "username"),
|
|
|
|
|
(6.967, 7.6, 4, "username"),
|
|
|
|
|
(7.733, 8.367, 5, "username"),
|
|
|
|
|
(8.667, 9.133, 6, "username"),
|
|
|
|
|
(9.733, 10.667, 7, "username"),
|
|
|
|
|
(11.6, 12.033, 8, "@everyone"),
|
|
|
|
|
(12.067, 13.0, 9, "@everyone"),
|
|
|
|
|
(13.033, 14.135, 10, "@everyone"),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# Build drawtext filters
|
|
|
|
|
drawtext_filters = []
|
|
|
|
|
for start, end, pos_id, text_type in text_entries:
|
|
|
|
|
x_coord, y_coord = positions[pos_id]
|
|
|
|
|
|
|
|
|
|
# Determine actual text content
|
|
|
|
|
text_content = f"@{username}" if text_type == "username" else text_type
|
|
|
|
|
|
|
|
|
|
x = f"{x_coord} - text_w/2"
|
|
|
|
|
y = f"{y_coord} - text_h/2"
|
|
|
|
|
|
|
|
|
|
filter_str = (
|
|
|
|
|
f"drawtext=text='{text_content}':"
|
|
|
|
|
f"fontfile='{font_path}':"
|
|
|
|
|
f"fontcolor=black:fontsize=30:x={x}:y={y}:"
|
|
|
|
|
f"enable='between(t,{start},{end})'"
|
|
|
|
|
)
|
|
|
|
|
drawtext_filters.append(filter_str)
|
|
|
|
|
|
|
|
|
|
vf_string = ",".join(drawtext_filters)
|
|
|
|
|
|
|
|
|
|
ffmpeg_command = [
|
|
|
|
|
"ffmpeg",
|
|
|
|
|
"-i", base_video_path,
|
|
|
|
|
"-vf", vf_string,
|
|
|
|
|
"-codec:a", "copy",
|
|
|
|
|
output_path
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
subprocess.run(ffmpeg_command, check=True)
|
feat: Implement comprehensive non-hierarchical logging system
- Created new logging infrastructure with per-component filtering
- Added 6 log levels: DEBUG, INFO, API, WARNING, ERROR, CRITICAL
- Implemented non-hierarchical level control (any combination can be enabled)
- Migrated 917 print() statements across 31 files to structured logging
- Created web UI (system.html) for runtime configuration with dark theme
- Added global level controls to enable/disable levels across all components
- Added timestamp format control (off/time/date/datetime options)
- Implemented log rotation (10MB per file, 5 backups)
- Added API endpoints for dynamic log configuration
- Configured HTTP request logging with filtering via api.requests component
- Intercepted APScheduler logs with proper formatting
- Fixed persistence paths to use /app/memory for Docker volume compatibility
- Fixed checkbox display bug in web UI (enabled_levels now properly shown)
- Changed System Settings button to open in same tab instead of new window
Components: bot, api, api.requests, autonomous, persona, vision, llm,
conversation, mood, dm, scheduled, gpu, media, server, commands,
sentiment, core, apscheduler
All settings persist across container restarts via JSON config.
2026-01-10 20:46:19 +02:00
|
|
|
logger.info("Video processed successfully with username overlays.")
|
2025-12-07 17:15:09 +02:00
|
|
|
except subprocess.CalledProcessError as e:
|
feat: Implement comprehensive non-hierarchical logging system
- Created new logging infrastructure with per-component filtering
- Added 6 log levels: DEBUG, INFO, API, WARNING, ERROR, CRITICAL
- Implemented non-hierarchical level control (any combination can be enabled)
- Migrated 917 print() statements across 31 files to structured logging
- Created web UI (system.html) for runtime configuration with dark theme
- Added global level controls to enable/disable levels across all components
- Added timestamp format control (off/time/date/datetime options)
- Implemented log rotation (10MB per file, 5 backups)
- Added API endpoints for dynamic log configuration
- Configured HTTP request logging with filtering via api.requests component
- Intercepted APScheduler logs with proper formatting
- Fixed persistence paths to use /app/memory for Docker volume compatibility
- Fixed checkbox display bug in web UI (enabled_levels now properly shown)
- Changed System Settings button to open in same tab instead of new window
Components: bot, api, api.requests, autonomous, persona, vision, llm,
conversation, mood, dm, scheduled, gpu, media, server, commands,
sentiment, core, apscheduler
All settings persist across container restarts via JSON config.
2026-01-10 20:46:19 +02:00
|
|
|
logger.error(f"FFmpeg error: {e}")
|