Enhance video file handling: support multiple formats (AVI, MP4, WEBM) in storage manager

This commit is contained in:
Alireza Vaezi
2025-08-05 13:53:28 -04:00
parent 37553163db
commit 14757807aa
2 changed files with 39 additions and 30 deletions

View File

@@ -97,7 +97,7 @@ while IFS= read -r -d '' avi_file; do
if [ -z "$duration" ] || [ "$duration" -eq 0 ]; then if [ -z "$duration" ] || [ "$duration" -eq 0 ]; then
print_warning "Could not determine video duration, converting without progress bar..." print_warning "Could not determine video duration, converting without progress bar..."
# Fallback to simple conversion without progress # Fallback to simple conversion without progress
if ffmpeg -i "$avi_file" -c:v libx264 -c:a aac -preset medium -crf 18 "$mp4_file" -y 2>/dev/null; then if ffmpeg -i "$avi_file" -c:v libx264 -c:a aac -preset medium -crf 18 -nostdin "$mp4_file" -y 2>/dev/null; then
echo echo
print_success "Converted: $avi_file -> $mp4_file" print_success "Converted: $avi_file -> $mp4_file"
converted_files=$((converted_files + 1)) converted_files=$((converted_files + 1))
@@ -117,7 +117,7 @@ while IFS= read -r -d '' avi_file; do
# Start ffmpeg conversion in background with progress output # Start ffmpeg conversion in background with progress output
ffmpeg -i "$avi_file" -c:v libx264 -c:a aac -preset medium -crf 18 \ ffmpeg -i "$avi_file" -c:v libx264 -c:a aac -preset medium -crf 18 \
-progress "$progress_file" -nostats -loglevel 0 "$mp4_file" -y & -progress "$progress_file" -nostats -loglevel 0 -nostdin "$mp4_file" -y &
ffmpeg_pid=$! ffmpeg_pid=$!

View File

@@ -211,7 +211,10 @@ class StorageManager:
storage_path = Path(camera_config.storage_path) storage_path = Path(camera_config.storage_path)
if storage_path.exists(): if storage_path.exists():
for video_file in storage_path.glob("*.avi"): # Scan for all supported video formats
video_extensions = ["*.avi", "*.mp4", "*.webm"]
for pattern in video_extensions:
for video_file in storage_path.glob(pattern):
if video_file.is_file() and str(video_file) not in indexed_files: if video_file.is_file() and str(video_file) not in indexed_files:
# Get file stats # Get file stats
stat = video_file.stat() stat = video_file.stat()
@@ -261,7 +264,10 @@ class StorageManager:
# Scan for video files in camera directory # Scan for video files in camera directory
if storage_path.exists(): if storage_path.exists():
for video_file in storage_path.glob("*.avi"): # Scan for all supported video formats
video_extensions = ["*.avi", "*.mp4", "*.webm"]
for pattern in video_extensions:
for video_file in storage_path.glob(pattern):
if video_file.is_file(): if video_file.is_file():
stats["total_files"] += 1 stats["total_files"] += 1
stats["cameras"][camera_name]["file_count"] += 1 stats["cameras"][camera_name]["file_count"] += 1
@@ -389,7 +395,10 @@ class StorageManager:
for camera_config in self.config.cameras: for camera_config in self.config.cameras:
storage_path = Path(camera_config.storage_path) storage_path = Path(camera_config.storage_path)
if storage_path.exists(): if storage_path.exists():
for video_file in storage_path.glob("*.avi"): # Check for all supported video formats
video_extensions = ["*.avi", "*.mp4", "*.webm"]
for pattern in video_extensions:
for video_file in storage_path.glob(pattern):
file_id = video_file.name file_id = video_file.name
if file_id not in self.file_index["files"]: if file_id not in self.file_index["files"]:
integrity_report["orphaned_files"].append(str(video_file)) integrity_report["orphaned_files"].append(str(video_file))