Fix sometimes overwriting existing edited videos
This commit is contained in:
@@ -2017,7 +2017,7 @@ class VideoEditor:
|
||||
# Add manual tracking position
|
||||
if base_pos:
|
||||
positions.append(base_pos)
|
||||
print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})")
|
||||
# print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})")
|
||||
|
||||
# Add template matching position
|
||||
if template_offset:
|
||||
@@ -5032,16 +5032,21 @@ class VideoEditor:
|
||||
extension = self.video_path.suffix
|
||||
|
||||
# Remove any existing _edited_ suffix to get clean base name
|
||||
clean_base = base_name.replace("_edited", "")
|
||||
clean_base = re.sub(r"_edited_\d{5}", "", base_name)
|
||||
|
||||
# Find next available number
|
||||
counter = 1
|
||||
while True:
|
||||
# Find next available number by scanning directory for existing files
|
||||
pattern = re.compile(rf"^{re.escape(clean_base)}_edited_(\d{{5}})\.")
|
||||
max_num = 0
|
||||
for file_path in directory.iterdir():
|
||||
if file_path.is_file():
|
||||
match = pattern.match(file_path.name)
|
||||
if match:
|
||||
num = int(match.group(1))
|
||||
max_num = max(max_num, num)
|
||||
|
||||
counter = max_num + 1
|
||||
new_name = f"{clean_base}_edited_{counter:05d}{extension}"
|
||||
output_path = directory / new_name
|
||||
if not output_path.exists():
|
||||
break
|
||||
counter += 1
|
||||
|
||||
success = self.render_video(str(output_path))
|
||||
elif key == 13: # Enter
|
||||
|
||||
Reference in New Issue
Block a user