diff options
author | Zaggy1024 <zaggy1024@gmail.com> | 2022-09-25 17:23:16 -0500 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-10-09 20:32:40 -0600 |
commit | b71d13be8280b7df95afb65b59fcfb557caab02e (patch) | |
tree | 0e6e8cb95353d02471164a720776f882aff0feff /Userland/Applications | |
parent | 63ba01cad270c7a29de47468ff773996d5fd0f1e (diff) | |
download | serenity-b71d13be8280b7df95afb65b59fcfb557caab02e.zip |
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.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/VideoPlayer/main.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
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 <LibCore/ArgsParser.h> +#include <LibCore/ElapsedTimer.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> #include <LibGUI/ImageWidget.h> @@ -15,10 +17,23 @@ ErrorOr<int> 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<int> 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(); |