Also don't load videos that have an edited variant

This commit is contained in:
2025-09-04 16:11:10 +02:00
parent 10eed9efcd
commit ad4130906b

View File

@@ -114,16 +114,31 @@ class VideoEditor:
def _get_video_files_from_directory(self, directory: Path) -> List[Path]:
"""Get all video files from a directory, sorted by name"""
video_files = []
video_files = set()
for file_path in directory.iterdir():
if (
file_path.is_file()
and file_path.suffix.lower() in self.VIDEO_EXTENSIONS
and not "_edited" in file_path.name
):
video_files.append(file_path)
return sorted(video_files)
video_files.add(file_path)
edited_videos = set()
for file_path in video_files:
if "_edited" in file_path.stem:
edited_videos.add(file_path)
non_edited_videos = set()
for file_path in video_files:
if "_edited" in file_path.stem:
continue
edited_equivalent = file_path.with_name(
f"{file_path.stem}_edited{file_path.suffix}"
)
if edited_equivalent in edited_videos:
continue
non_edited_videos.add(file_path)
return sorted(non_edited_videos)
def _load_video(self, video_path: Path):
"""Load a video file and initialize video properties"""
if hasattr(self, "cap") and self.cap:
@@ -371,47 +386,123 @@ class VideoEditor:
# Apply fade alpha to colors
bg_color = tuple(int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_BG)
border_color = tuple(int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_BORDER)
border_color = tuple(
int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_BORDER
)
if self.progress_bar_complete:
fill_color = tuple(int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_FILL)
fill_color = tuple(
int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_FILL
)
else:
fill_color = tuple(int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_PROGRESS)
fill_color = tuple(
int(c * fade_alpha) for c in self.PROGRESS_BAR_COLOR_PROGRESS
)
# Draw background
cv2.rectangle(frame, (bar_x, bar_y), (bar_x + bar_width, bar_y + self.PROGRESS_BAR_HEIGHT), bg_color, -1)
cv2.rectangle(
frame,
(bar_x, bar_y),
(bar_x + bar_width, bar_y + self.PROGRESS_BAR_HEIGHT),
bg_color,
-1,
)
# Draw progress fill
fill_width = int(bar_width * self.progress_bar_progress)
if fill_width > 0:
cv2.rectangle(frame, (bar_x, bar_y), (bar_x + fill_width, bar_y + self.PROGRESS_BAR_HEIGHT), fill_color, -1)
cv2.rectangle(
frame,
(bar_x, bar_y),
(bar_x + fill_width, bar_y + self.PROGRESS_BAR_HEIGHT),
fill_color,
-1,
)
# Draw border
cv2.rectangle(frame, (bar_x, bar_y), (bar_x + bar_width, bar_y + self.PROGRESS_BAR_HEIGHT), border_color, 2)
cv2.rectangle(
frame,
(bar_x, bar_y),
(bar_x + bar_width, bar_y + self.PROGRESS_BAR_HEIGHT),
border_color,
2,
)
# Draw progress percentage on the left
percentage_text = f"{self.progress_bar_progress * 100:.1f}%"
text_color = tuple(int(255 * fade_alpha) for _ in range(3))
cv2.putText(frame, percentage_text, (bar_x + 12, bar_y + 22), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 4)
cv2.putText(frame, percentage_text, (bar_x + 10, bar_y + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 2)
cv2.putText(
frame,
percentage_text,
(bar_x + 12, bar_y + 22),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
(0, 0, 0),
4,
)
cv2.putText(
frame,
percentage_text,
(bar_x + 10, bar_y + 20),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
text_color,
2,
)
# Draw FPS on the right if available
if self.progress_bar_fps > 0:
fps_text = f"{self.progress_bar_fps:.1f} FPS"
fps_text_size = cv2.getTextSize(fps_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)[0]
fps_text_size = cv2.getTextSize(fps_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)[
0
]
fps_x = bar_x + bar_width - fps_text_size[0] - 10
cv2.putText(frame, fps_text, (fps_x + 2, bar_y + 22), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 4)
cv2.putText(frame, fps_text, (fps_x, bar_y + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 2)
cv2.putText(
frame,
fps_text,
(fps_x + 2, bar_y + 22),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
(0, 0, 0),
4,
)
cv2.putText(
frame,
fps_text,
(fps_x, bar_y + 20),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
text_color,
2,
)
# Draw main text in center
if self.progress_bar_text:
text_size = cv2.getTextSize(self.progress_bar_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)[0]
text_size = cv2.getTextSize(
self.progress_bar_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1
)[0]
text_x = bar_x + (bar_width - text_size[0]) // 2
text_y = bar_y + 20
# Draw text shadow for better visibility
cv2.putText(frame, self.progress_bar_text, (text_x + 2, text_y + 2), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 4)
cv2.putText(frame, self.progress_bar_text, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 2)
cv2.putText(
frame,
self.progress_bar_text,
(text_x + 2, text_y + 2),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
(0, 0, 0),
4,
)
cv2.putText(
frame,
self.progress_bar_text,
(text_x, text_y),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
text_color,
2,
)
def draw_timeline(self, frame):
"""Draw timeline at the bottom of the frame"""
@@ -961,7 +1052,9 @@ class VideoEditor:
last_progress_update = current_time
# Update display more frequently to show progress bar
if current_time - last_display_update > 0.1: # Update display every 100ms
if (
current_time - last_display_update > 0.1
): # Update display every 100ms
self.display_current_frame()
cv2.waitKey(1) # Allow OpenCV to process events
last_display_update = current_time
@@ -973,7 +1066,11 @@ class VideoEditor:
avg_fps = total_frames_written / total_time if total_time > 0 else 0
# Complete the progress bar
self.update_progress_bar(1.0, f"Complete! Rendered {total_frames_written} frames in {total_time:.1f}s", avg_fps)
self.update_progress_bar(
1.0,
f"Complete! Rendered {total_frames_written} frames in {total_time:.1f}s",
avg_fps,
)
print(f"\nVideo rendered successfully to {output_path}")
print(