From fa101d6bf6da5288dcbe0a7f7a94afa76c1b7033 Mon Sep 17 00:00:00 2001 From: FalseHonesty Date: Sat, 5 Jun 2021 16:42:25 -0400 Subject: [PATCH] VideoPlayer: Create application to parse (and eventually play) videos This application will eventually be able to actually play videos, but for now it is used to parse and dump decoded data from the VP9 decoder. --- Userland/Applications/CMakeLists.txt | 1 + .../Applications/VideoPlayer/CMakeLists.txt | 6 +++ Userland/Applications/VideoPlayer/main.cpp | 53 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Userland/Applications/VideoPlayer/CMakeLists.txt create mode 100644 Userland/Applications/VideoPlayer/main.cpp diff --git a/Userland/Applications/CMakeLists.txt b/Userland/Applications/CMakeLists.txt index 9a9674c5f1..0db8bcbcca 100644 --- a/Userland/Applications/CMakeLists.txt +++ b/Userland/Applications/CMakeLists.txt @@ -28,4 +28,5 @@ add_subdirectory(SystemMonitor) add_subdirectory(ThemeEditor) add_subdirectory(Terminal) add_subdirectory(TextEditor) +add_subdirectory(VideoPlayer) add_subdirectory(Welcome) diff --git a/Userland/Applications/VideoPlayer/CMakeLists.txt b/Userland/Applications/VideoPlayer/CMakeLists.txt new file mode 100644 index 0000000000..f9f1a7422f --- /dev/null +++ b/Userland/Applications/VideoPlayer/CMakeLists.txt @@ -0,0 +1,6 @@ +set(SOURCES + main.cpp +) + +serenity_bin(VideoPlayer) +target_link_libraries(VideoPlayer LibVideo LibAudio LibGUI) diff --git a/Userland/Applications/VideoPlayer/main.cpp b/Userland/Applications/VideoPlayer/main.cpp new file mode 100644 index 0000000000..5978a4f1af --- /dev/null +++ b/Userland/Applications/VideoPlayer/main.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021, Hunter Salyer + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + auto app = GUI::Application::construct(argc, argv); + auto window = GUI::Window::construct(); + + auto document = Video::MatroskaReader::parse_matroska_from_file("/home/anon/Videos/test-webm.webm"); + const auto& optional_track = document->track_for_track_type(Video::TrackEntry::TrackType::Video); + if (!optional_track.has_value()) + return 1; + const auto& track = optional_track.value(); + const auto video_track = track.video_track().value(); + + auto image = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize(video_track.pixel_height, video_track.pixel_width)); + auto& main_widget = window->set_main_widget(); + main_widget.set_fill_with_background_color(true); + main_widget.set_layout(); + auto& image_widget = main_widget.add(); + image_widget.set_bitmap(image); + image_widget.set_fixed_size(video_track.pixel_height, video_track.pixel_width); + main_widget.add_child(image_widget); + + Video::VP9::Decoder vp9_decoder; + for (const auto& cluster : document->clusters()) { + for (const auto& block : cluster.blocks()) { + if (block.track_number() != track.track_number()) + continue; + + const auto& frame = block.frame(0); + dbgln("Reading frame 0 from block @ {}", block.timestamp()); + vp9_decoder.parse_frame(frame); + vp9_decoder.dump_info(); + } + } + + window->show(); + return app->exec(); +}