Skip to content

Commit

Permalink
Add a rewind option to wiggle
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Dec 10, 2023
1 parent 0638f55 commit 58042c4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions charidotella/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ def run_generators(configuration: dict[str, typing.Any]):
"forward_duration": utilities.timestamp_to_timecode(
1000000
),
"rewind": True,
"tau_to_frametime_ratio": 3.0,
"style": "cumulative",
"idle_color": "#191919",
Expand Down
47 changes: 27 additions & 20 deletions charidotella/tasks/wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,34 @@ def run(
)
sorted_frames = temporary_directory / "sorted_frames"
sorted_frames.mkdir(exist_ok=True)
paths: list[pathlib.Path] = []
for path in sorted(base_frames.iterdir()):
if path.suffix == ".ppm":
paths.append(path)
selected_paths: list[pathlib.Path] = []
if len(paths) >= round(parameters["tau_to_frametime_ratio"]) + 2:
for index, path in enumerate(paths):
if (
index >= round(parameters["tau_to_frametime_ratio"])
and index % 2 == 1
):
selected_paths.append(path)
if parameters["rewind"]:
paths: list[pathlib.Path] = []
for path in sorted(base_frames.iterdir()):
if path.suffix == ".ppm":
paths.append(path)
selected_paths: list[pathlib.Path] = []
if len(paths) >= round(parameters["tau_to_frametime_ratio"]) + 2:
for index, path in enumerate(paths):
if (
index >= round(parameters["tau_to_frametime_ratio"])
and index % 2 == 1
):
selected_paths.append(path)
else:
selected_paths = paths
output_index = 0
for path in selected_paths:
shutil.copyfile(path, sorted_frames / f"{output_index:>06d}.ppm")
output_index += 1
for path in reversed(selected_paths[1:-1]):
path.replace(sorted_frames / f"{output_index:>06d}.ppm")
output_index += 1
else:
selected_paths = paths
output_index = 0
for path in selected_paths:
shutil.copyfile(path, sorted_frames / f"{output_index:>06d}.ppm")
output_index += 1
for path in reversed(selected_paths[1:-1]):
path.replace(sorted_frames / f"{output_index:>06d}.ppm")
output_index += 1
output_index = 0
for path in sorted(base_frames.iterdir()):
if path.suffix == ".ppm":
shutil.copyfile(path, sorted_frames / f"{output_index:>06d}.ppm")
output_index += 1
subprocess.run(
[
parameters["ffmpeg"],
Expand Down
2 changes: 1 addition & 1 deletion charidotella/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.0.0"
__version__ = "3.1.0"
4 changes: 4 additions & 0 deletions configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@
"forward_duration": {
"type": ["string", "integer"]
},
"rewind": {
"type": ["boolean"]
},
"icon": {
"type": "string"
},
Expand Down Expand Up @@ -576,6 +579,7 @@
"type",
"icon",
"forward_duration",
"rewind",
"tau_to_frametime_ratio",
"style",
"on_color",
Expand Down

0 comments on commit 58042c4

Please sign in to comment.