Enhance video file handling: support multiple formats (AVI, MP4, WEBM) in storage manager
This commit is contained in:
@@ -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=$!
|
||||||
|
|
||||||
|
|||||||
@@ -211,21 +211,24 @@ 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
|
||||||
if video_file.is_file() and str(video_file) not in indexed_files:
|
video_extensions = ["*.avi", "*.mp4", "*.webm"]
|
||||||
# Get file stats
|
for pattern in video_extensions:
|
||||||
stat = video_file.stat()
|
for video_file in storage_path.glob(pattern):
|
||||||
file_mtime = datetime.fromtimestamp(stat.st_mtime)
|
if video_file.is_file() and str(video_file) not in indexed_files:
|
||||||
|
# Get file stats
|
||||||
|
stat = video_file.stat()
|
||||||
|
file_mtime = datetime.fromtimestamp(stat.st_mtime)
|
||||||
|
|
||||||
# Apply date filters
|
# Apply date filters
|
||||||
if start_date and file_mtime < start_date:
|
if start_date and file_mtime < start_date:
|
||||||
continue
|
continue
|
||||||
if end_date and file_mtime > end_date:
|
if end_date and file_mtime > end_date:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Create file info for unindexed file
|
# Create file info for unindexed file
|
||||||
file_info = {"camera_name": camera_config.name, "filename": str(video_file), "file_id": video_file.name, "start_time": file_mtime.isoformat(), "end_time": None, "file_size_bytes": stat.st_size, "duration_seconds": None, "machine_trigger": None, "status": "unknown", "created_at": file_mtime.isoformat()} # We don't know if it's completed or not
|
file_info = {"camera_name": camera_config.name, "filename": str(video_file), "file_id": video_file.name, "start_time": file_mtime.isoformat(), "end_time": None, "file_size_bytes": stat.st_size, "duration_seconds": None, "machine_trigger": None, "status": "unknown", "created_at": file_mtime.isoformat()} # We don't know if it's completed or not
|
||||||
files.append(file_info)
|
files.append(file_info)
|
||||||
|
|
||||||
# Sort by start time (newest first)
|
# Sort by start time (newest first)
|
||||||
files.sort(key=lambda x: x["start_time"], reverse=True)
|
files.sort(key=lambda x: x["start_time"], reverse=True)
|
||||||
@@ -261,18 +264,21 @@ 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
|
||||||
if video_file.is_file():
|
video_extensions = ["*.avi", "*.mp4", "*.webm"]
|
||||||
stats["total_files"] += 1
|
for pattern in video_extensions:
|
||||||
stats["cameras"][camera_name]["file_count"] += 1
|
for video_file in storage_path.glob(pattern):
|
||||||
|
if video_file.is_file():
|
||||||
|
stats["total_files"] += 1
|
||||||
|
stats["cameras"][camera_name]["file_count"] += 1
|
||||||
|
|
||||||
# Get file size
|
# Get file size
|
||||||
try:
|
try:
|
||||||
file_size = video_file.stat().st_size
|
file_size = video_file.stat().st_size
|
||||||
stats["total_size_bytes"] += file_size
|
stats["total_size_bytes"] += file_size
|
||||||
stats["cameras"][camera_name]["total_size_bytes"] += file_size
|
stats["cameras"][camera_name]["total_size_bytes"] += file_size
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning(f"Could not get size for {video_file}: {e}")
|
self.logger.warning(f"Could not get size for {video_file}: {e}")
|
||||||
|
|
||||||
# Add duration information from index if available
|
# Add duration information from index if available
|
||||||
for file_info in self.file_index["files"].values():
|
for file_info in self.file_index["files"].values():
|
||||||
@@ -389,10 +395,13 @@ 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
|
||||||
file_id = video_file.name
|
video_extensions = ["*.avi", "*.mp4", "*.webm"]
|
||||||
if file_id not in self.file_index["files"]:
|
for pattern in video_extensions:
|
||||||
integrity_report["orphaned_files"].append(str(video_file))
|
for video_file in storage_path.glob(pattern):
|
||||||
|
file_id = video_file.name
|
||||||
|
if file_id not in self.file_index["files"]:
|
||||||
|
integrity_report["orphaned_files"].append(str(video_file))
|
||||||
|
|
||||||
# Save updated index if fixes were made
|
# Save updated index if fixes were made
|
||||||
if integrity_report["fixed_issues"] > 0:
|
if integrity_report["fixed_issues"] > 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user