From cfcee1a5d8e5068cdc5171b01beb9f9e6251e51e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 27 Oct 2024 01:52:22 +0200 Subject: Add option to change video resolution --- src/Config.cpp | 9 +++++ src/Overlay.cpp | 6 ++- src/gui/CheckBox.cpp | 8 +++- src/gui/SettingsPage.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 117 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index b9319aa..0e256a9 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -36,9 +36,12 @@ namespace gsr { {"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option}, {"streaming.record_options.record_area_width", &config.streaming_config.record_options.record_area_width}, {"streaming.record_options.record_area_height", &config.streaming_config.record_options.record_area_height}, + {"streaming.record_options.video_width", &config.streaming_config.record_options.video_width}, + {"streaming.record_options.video_height", &config.streaming_config.record_options.video_height}, {"streaming.record_options.fps", &config.streaming_config.record_options.fps}, {"streaming.record_options.video_bitrate", &config.streaming_config.record_options.video_bitrate}, {"streaming.record_options.merge_audio_tracks", &config.streaming_config.record_options.merge_audio_tracks}, + {"streaming.record_options.change_video_resolution", &config.streaming_config.record_options.change_video_resolution}, {"streaming.record_options.audio_track", &config.streaming_config.record_options.audio_tracks}, {"streaming.record_options.color_range", &config.streaming_config.record_options.color_range}, {"streaming.record_options.video_quality", &config.streaming_config.record_options.video_quality}, @@ -61,9 +64,12 @@ namespace gsr { {"record.record_options.record_area_option", &config.record_config.record_options.record_area_option}, {"record.record_options.record_area_width", &config.record_config.record_options.record_area_width}, {"record.record_options.record_area_height", &config.record_config.record_options.record_area_height}, + {"record.record_options.video_width", &config.record_config.record_options.video_width}, + {"record.record_options.video_height", &config.record_config.record_options.video_height}, {"record.record_options.fps", &config.record_config.record_options.fps}, {"record.record_options.video_bitrate", &config.record_config.record_options.video_bitrate}, {"record.record_options.merge_audio_tracks", &config.record_config.record_options.merge_audio_tracks}, + {"record.record_options.change_video_resolution", &config.record_config.record_options.change_video_resolution}, {"record.record_options.audio_track", &config.record_config.record_options.audio_tracks}, {"record.record_options.color_range", &config.record_config.record_options.color_range}, {"record.record_options.video_quality", &config.record_config.record_options.video_quality}, @@ -84,9 +90,12 @@ namespace gsr { {"replay.record_options.record_area_option", &config.replay_config.record_options.record_area_option}, {"replay.record_options.record_area_width", &config.replay_config.record_options.record_area_width}, {"replay.record_options.record_area_height", &config.replay_config.record_options.record_area_height}, + {"replay.record_options.video_width", &config.replay_config.record_options.video_width}, + {"replay.record_options.video_height", &config.replay_config.record_options.video_height}, {"replay.record_options.fps", &config.replay_config.record_options.fps}, {"replay.record_options.video_bitrate", &config.replay_config.record_options.video_bitrate}, {"replay.record_options.merge_audio_tracks", &config.replay_config.record_options.merge_audio_tracks}, + {"replay.record_options.change_video_resolution", &config.replay_config.record_options.change_video_resolution}, {"replay.record_options.audio_track", &config.replay_config.record_options.audio_tracks}, {"replay.record_options.color_range", &config.replay_config.record_options.color_range}, {"replay.record_options.video_quality", &config.replay_config.record_options.video_quality}, diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 204ff6f..c0acad4 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -704,9 +704,13 @@ namespace gsr { const std::string output_file = config->record_config.save_directory + "/Video_" + get_date_str() + "." + container_to_file_extension(config->record_config.container.c_str()); const std::string audio_tracks_merged = merge_audio_tracks(config->record_config.record_options.audio_tracks); const std::string framerate_mode = config->record_config.record_options.framerate_mode == "auto" ? "vfr" : config->record_config.record_options.framerate_mode; + char region[64]; snprintf(region, sizeof(region), "%dx%d", (int)config->record_config.record_options.record_area_width, (int)config->record_config.record_options.record_area_height); + if(config->record_config.record_options.record_area_option != "focused" && config->record_config.record_options.change_video_resolution) + snprintf(region, sizeof(region), "%dx%d", (int)config->record_config.record_options.video_width, (int)config->record_config.record_options.video_height); + std::vector args = { "gpu-screen-recorder", "-w", config->record_config.record_options.record_area_option.c_str(), "-c", config->record_config.container.c_str(), @@ -729,7 +733,7 @@ namespace gsr { args.push_back(config->record_config.record_options.video_quality.c_str()); } - if(config->record_config.record_options.record_area_option == "window" || config->record_config.record_options.record_area_option == "focused") { + if(config->record_config.record_options.record_area_option == "focused" || config->record_config.record_options.change_video_resolution) { args.push_back("-s"); args.push_back(region); } diff --git a/src/gui/CheckBox.cpp b/src/gui/CheckBox.cpp index f1c84ff..d602cca 100644 --- a/src/gui/CheckBox.cpp +++ b/src/gui/CheckBox.cpp @@ -42,8 +42,12 @@ namespace gsr { if(event.type == mgl::Event::MouseButtonPressed && event.mouse_button.button == mgl::Mouse::Left) { const bool clicked_inside = mgl::FloatRect(position + offset, get_size()).contains({ (float)event.mouse_button.x, (float)event.mouse_button.y }); - if(clicked_inside) + if(clicked_inside) { checked = !checked; + if(on_changed) + on_changed(checked); + return false; + } } return true; } @@ -105,6 +109,8 @@ namespace gsr { this->checked = checked; if(!animated) toggle_animation_value = checked ? 1.0f : 0.0f; + if(on_changed) + on_changed(checked); } bool CheckBox::is_checked() const { diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index fb2cc68..11571dc 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -111,6 +111,36 @@ namespace gsr { return area_size_list; } + std::unique_ptr SettingsPage::create_video_width_entry() { + auto video_width_entry = std::make_unique(&get_theme().body_font, "1920", get_theme().body_font.get_character_size() * 3); + video_width_entry->validate_handler = create_entry_validator_integer_in_range(1, 1 << 15); + video_width_entry_ptr = video_width_entry.get(); + return video_width_entry; + } + + std::unique_ptr SettingsPage::create_video_height_entry() { + auto video_height_entry = std::make_unique(&get_theme().body_font, "1080", get_theme().body_font.get_character_size() * 3); + video_height_entry->validate_handler = create_entry_validator_integer_in_range(1, 1 << 15); + video_height_entry_ptr = video_height_entry.get(); + return video_height_entry; + } + + std::unique_ptr SettingsPage::create_video_resolution() { + auto area_size_params_list = std::make_unique(List::Orientation::HORIZONTAL, List::Alignment::CENTER); + area_size_params_list->add_widget(create_video_width_entry()); + area_size_params_list->add_widget(std::make_unique