Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Lanczos scaling if frames need to be scaled #3

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions matplotloom/loom.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ def save_frame(self, fig, frame_number=None):
plt.close(fig)

def save_video(self):
# See: https://github.com/ali-ramadhan/matplotloom/issues/1
scale_filter = "scale='if(mod(iw,2),-2,iw)':'if(mod(ih,2),-2,ih)':flags=lanczos"

if self.file_format == "mp4":
command = [
"ffmpeg",
"-y",
"-framerate", str(self.fps),
"-i", str(self.frames_directory / "frame_%06d.png"),
# See: https://github.com/ali-ramadhan/matplotloom/issues/1
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2",
"-vf", scale_filter,
"-c:v", "libx264",
"-pix_fmt", "yuv420p",
str(self.output_filepath)
Expand All @@ -94,9 +96,8 @@ def save_video(self):
"-framerate", str(self.fps),
"-f", "image2",
"-i", str(self.frames_directory / "frame_%06d.png"),
# See: https://github.com/ali-ramadhan/matplotloom/issues/1 for scale filter
# See: https://superuser.com/a/556031 for the rest of the filters
"-vf", 'scale=trunc(iw/2)*2:trunc(ih/2)*2,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse',
# See: https://superuser.com/a/556031 for the split and palette filters
"-vf", f"{scale_filter},split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse",
str(self.output_filepath)
]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "matplotloom"
version = "0.5.0"
version = "0.6.0"
description = "Weave your frames into matplotlib animations."
authors = ["ali-ramadhan <ali.hh.ramadhan@gmail.com>"]
license = "MIT"
Expand Down