From 19095cddf6280d199cac28abacebbeefbe832361 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 26 Nov 2025 19:20:41 -0500 Subject: [PATCH] animation: Add --frame-duration-ms flag This allows overriding the frame duration, which is especially useful when making an animation out of several single-frame images. --- Userland/Utilities/animation.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Utilities/animation.cpp b/Userland/Utilities/animation.cpp index c3cc2f74432..08d4b0cb739 100644 --- a/Userland/Utilities/animation.cpp +++ b/Userland/Utilities/animation.cpp @@ -18,6 +18,7 @@ struct Options { StringView out_path; bool write_full_frames { false }; Gfx::AnimationWriter::AllowInterFrameCompression allow_inter_frame_compression { Gfx::AnimationWriter::AllowInterFrameCompression::Yes }; + Optional frame_duration_ms; }; static ErrorOr parse_options(Main::Arguments arguments) @@ -36,6 +37,8 @@ static ErrorOr parse_options(Main::Arguments arguments) bool inter_frame_compression_none = false; args_parser.add_option(inter_frame_compression_none, "Do not store incremental frames. Produces larger files.", "inter-frame-compression=none"); + args_parser.add_option(options.frame_duration_ms, "Frame duration in ms (default: from input)", "frame-duration-ms", {}, {}); + args_parser.parse(arguments); if (options.out_path.is_empty()) @@ -95,9 +98,7 @@ ErrorOr serenity_main(Main::Arguments arguments) for (auto const& decoder : decoders) { for (size_t i = 0; i < decoder->frame_count(); ++i) { auto frame = TRY(decoder->frame(i)); - - // FIXME: Make overridable, at least for single-frame inputs? - auto frame_duration = frame.duration; + auto frame_duration = options.frame_duration_ms.value_or(frame.duration); if (options.write_full_frames) { TRY(animation_writer->add_frame(*frame.image, frame_duration));