From b71d13be8280b7df95afb65b59fcfb557caab02e Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 25 Sep 2022 17:23:16 -0500 Subject: [PATCH] VideoPlayer: Allow display of multiple frames by clicking the image For testing purposes, this allows opening of any filename by passing it as an argument. Additionally, there is a --benchmark option that will just call decode for 100 frames and then exit, printing the time spent in the decoder. --- Userland/Applications/VideoPlayer/main.cpp | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/VideoPlayer/main.cpp b/Userland/Applications/VideoPlayer/main.cpp index 8ef8162980..9e129e2c7f 100644 --- a/Userland/Applications/VideoPlayer/main.cpp +++ b/Userland/Applications/VideoPlayer/main.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include @@ -15,10 +17,23 @@ ErrorOr serenity_main(Main::Arguments arguments) { + bool benchmark = false; + StringView filename = "/home/anon/Videos/test-webm.webm"sv; + + Core::ArgsParser args_parser; + args_parser.add_option(benchmark, "Benchmark the video decoder.", "benchmark", 'b'); + args_parser.add_positional_argument(filename, "The video file to display.", "filename", Core::ArgsParser::Required::No); + args_parser.parse(arguments); + auto app = TRY(GUI::Application::try_create(arguments)); auto window = TRY(GUI::Window::try_create()); - auto document = Video::MatroskaReader::parse_matroska_from_file("/home/anon/Videos/test-webm.webm"sv); + auto document = Video::MatroskaReader::parse_matroska_from_file(filename); + // FIXME: MatroskaReader should use ErrorOr + if (!document) { + outln("{} could not be read", filename); + return 1; + } auto const& optional_track = document->track_for_track_type(Video::TrackEntry::TrackType::Video); if (!optional_track.has_value()) return 1; @@ -105,6 +120,18 @@ ErrorOr serenity_main(Main::Arguments arguments) frame_number++; }; + image_widget->set_fixed_size(video_track.pixel_width, video_track.pixel_height); + image_widget->on_click = [&]() { display_next_frame(); }; + + if (benchmark) { + auto timer = Core::ElapsedTimer::start_new(); + for (auto i = 0; i < 100; i++) + display_next_frame(); + auto elapsed_time = timer.elapsed_time(); + outln("Decoding 100 frames took {} ms", elapsed_time.to_milliseconds()); + return 0; + } + display_next_frame(); window->show();