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