Skip to content
Snippets Groups Projects
Commit d5ac5316 authored by mhocke's avatar mhocke
Browse files

Fix broken file overwrite dialog for video rendering

`input` doesn't work correctly after the tqdm pbar was updated. (The prompt is not displayed.)
The fix is to ask about overwriting before rendering starts.
parent f8561bfb
Branches
Tags
1 merge request!50Merge dev_mathis with multiple changes
Pipeline #66317 failed
......@@ -1015,6 +1015,7 @@ class File(h5py.File):
"""
if video_path is not None:
video_path = Path(video_path)
try:
run(["ffmpeg"], capture_output=True)
except Exception as e:
......@@ -1307,13 +1308,12 @@ class File(h5py.File):
min_view = np.max((np.max(start_pose, axis=0) - np.min(start_pose, axis=0))[:2])
self.view_size = np.max([options["view_size"], min_view + options["margin"]])
if video_path is not None:
pbar = tqdm(range(n_frames))
pbar = tqdm(range(n_frames)) if video_path is not None else None
def update(frame):
output_list = []
if "pbar" in locals().keys():
if pbar:
pbar.update(1)
pbar.refresh()
......@@ -1433,6 +1433,14 @@ class File(h5py.File):
+ swarm_center
)
if video_path is not None:
if video_path.exists():
if input(f"Video {str(video_path)} exists. Overwrite? (y/n)") == "y":
video_path.unlink()
else:
return
print(f"saving video to {video_path}")
print(f"Preparing to render n_frames: {n_frames}")
ani = animation.FuncAnimation(
......@@ -1446,20 +1454,8 @@ class File(h5py.File):
)
if video_path is not None:
# if i % (n / 40) == 0:
# print(f"Saving frame {i} of {n} ({100*i/n:.1f}%)")
video_path = Path(video_path)
if video_path.exists():
y = input(f"Video {str(video_path)} exists. Overwrite? (y/n)")
if y == "y":
video_path.unlink()
if not video_path.exists():
print(f"saving video to {video_path}")
writervideo = animation.FFMpegWriter(fps=self.frequency)
ani.save(video_path, writer=writervideo, dpi=options["dpi"])
writervideo = animation.FFMpegWriter(fps=self.frequency)
ani.save(video_path, writer=writervideo, dpi=options["dpi"])
plt.close()
else:
plt.show()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment