diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-10-27 01:52:22 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-10-27 01:54:37 +0200 |
commit | cfcee1a5d8e5068cdc5171b01beb9f9e6251e51e (patch) | |
tree | d2237ae86f9c41bb74ae05be25f5209857e1a132 /src | |
parent | 1d2fc77cfcd3d40c3a382d3f5f8e6c28e8b38da9 (diff) |
Add option to change video resolution
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.cpp | 9 | ||||
-rw-r--r-- | src/Overlay.cpp | 6 | ||||
-rw-r--r-- | src/gui/CheckBox.cpp | 8 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 98 |
4 files changed, 117 insertions, 4 deletions
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<const char*> 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<Entry> SettingsPage::create_video_width_entry() { + auto video_width_entry = std::make_unique<Entry>(&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<Entry> SettingsPage::create_video_height_entry() { + auto video_height_entry = std::make_unique<Entry>(&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<List> SettingsPage::create_video_resolution() { + auto area_size_params_list = std::make_unique<List>(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<Label>(&get_theme().body_font, "x", get_theme().text_color)); + area_size_params_list->add_widget(create_video_height_entry()); + return area_size_params_list; + } + + std::unique_ptr<List> SettingsPage::create_video_resolution_section() { + auto video_resolution_list = std::make_unique<List>(List::Orientation::VERTICAL); + video_resolution_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Video resolution:", get_theme().text_color)); + video_resolution_list->add_widget(create_video_resolution()); + video_resolution_list_ptr = video_resolution_list.get(); + return video_resolution_list; + } + std::unique_ptr<CheckBox> SettingsPage::create_restore_portal_session_checkbox() { auto restore_portal_session_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Restore portal session"); restore_portal_session_checkbox->set_checked(true); @@ -126,14 +156,25 @@ namespace gsr { return restore_portal_session_list; } + std::unique_ptr<Widget> SettingsPage::create_change_video_resolution_section() { + auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Change video resolution"); + change_video_resolution_checkbox_ptr = checkbox.get(); + return checkbox; + } + std::unique_ptr<Widget> SettingsPage::create_capture_target(const GsrInfo &gsr_info) { - // TODO: List::Alignment::Center causes 1 frame glitch when switching record area but only the first time + auto ll = std::make_unique<List>(List::Orientation::VERTICAL); + auto capture_target_list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER); capture_target_list->add_widget(create_record_area(gsr_info)); capture_target_list->add_widget(create_select_window()); capture_target_list->add_widget(create_area_size_section()); + capture_target_list->add_widget(create_video_resolution_section()); capture_target_list->add_widget(create_restore_portal_session_section()); - return std::make_unique<Subsection>("Record area", std::move(capture_target_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)); + + ll->add_widget(std::move(capture_target_list)); + ll->add_widget(create_change_video_resolution_section()); + return std::make_unique<Subsection>("Record area", std::move(ll), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)); } std::unique_ptr<ComboBox> SettingsPage::create_audio_track_selection_checkbox() { @@ -386,9 +427,16 @@ namespace gsr { const bool portal_selected = id == "portal"; select_window_list_ptr->set_visible(window_selected); area_size_list_ptr->set_visible(focused_selected); + video_resolution_list_ptr->set_visible(!focused_selected && change_video_resolution_checkbox_ptr->is_checked()); + change_video_resolution_checkbox_ptr->set_visible(!focused_selected); restore_portal_session_list_ptr->set_visible(portal_selected); }; + change_video_resolution_checkbox_ptr->on_changed = [this](bool checked) { + const bool focused_selected = record_area_box_ptr->get_selected_id() == "focused"; + video_resolution_list_ptr->set_visible(!focused_selected && checked); + }; + video_quality_box_ptr->on_selection_changed = [this](const std::string &text, const std::string &id) { (void)text; const bool custom_selected = id == "custom"; @@ -717,6 +765,7 @@ namespace gsr { void SettingsPage::load_common(RecordOptions &record_options) { record_area_box_ptr->set_selected_item(record_options.record_area_option); merge_audio_tracks_checkbox_ptr->set_checked(record_options.merge_audio_tracks); + change_video_resolution_checkbox_ptr->set_checked(record_options.change_video_resolution); load_audio_tracks(record_options); color_range_box_ptr->set_selected_item(record_options.color_range); @@ -730,6 +779,18 @@ namespace gsr { record_cursor_checkbox_ptr->set_checked(record_options.record_cursor); restore_portal_session_checkbox_ptr->set_checked(record_options.restore_portal_session); + if(record_options.record_area_width == 0) + record_options.record_area_width = 1920; + + if(record_options.record_area_height == 0) + record_options.record_area_height = 1080; + + if(record_options.video_width == 0) + record_options.video_width = 1920; + + if(record_options.video_height == 0) + record_options.video_height = 1080; + if(record_options.record_area_width < 32) record_options.record_area_width = 32; area_width_entry_ptr->set_text(std::to_string(record_options.record_area_width)); @@ -738,6 +799,14 @@ namespace gsr { record_options.record_area_height = 32; area_height_entry_ptr->set_text(std::to_string(record_options.record_area_height)); + if(record_options.video_width < 32) + record_options.video_width = 32; + video_width_entry_ptr->set_text(std::to_string(record_options.video_width)); + + if(record_options.video_height < 32) + record_options.video_height = 32; + video_height_entry_ptr->set_text(std::to_string(record_options.video_height)); + if(record_options.fps < 1) record_options.fps = 1; framerate_entry_ptr->set_text(std::to_string(record_options.fps)); @@ -793,9 +862,12 @@ namespace gsr { record_options.record_area_option = record_area_box_ptr->get_selected_id(); record_options.record_area_width = atoi(area_width_entry_ptr->get_text().c_str()); record_options.record_area_height = atoi(area_height_entry_ptr->get_text().c_str()); + record_options.video_width = atoi(video_width_entry_ptr->get_text().c_str()); + record_options.video_height = atoi(video_height_entry_ptr->get_text().c_str()); record_options.fps = atoi(framerate_entry_ptr->get_text().c_str()); record_options.video_bitrate = atoi(video_bitrate_entry_ptr->get_text().c_str()); record_options.merge_audio_tracks = merge_audio_tracks_checkbox_ptr->is_checked(); + record_options.change_video_resolution = change_video_resolution_checkbox_ptr->is_checked(); save_audio_tracks(record_options.audio_tracks, audio_devices_list_ptr); record_options.color_range = color_range_box_ptr->get_selected_id(); record_options.video_quality = video_quality_box_ptr->get_selected_id(); @@ -808,6 +880,18 @@ namespace gsr { record_options.record_cursor = record_cursor_checkbox_ptr->is_checked(); record_options.restore_portal_session = restore_portal_session_checkbox_ptr->is_checked(); + if(record_options.record_area_width == 0) + record_options.record_area_width = 1920; + + if(record_options.record_area_height == 0) + record_options.record_area_height = 1080; + + if(record_options.video_width == 0) + record_options.video_width = 1920; + + if(record_options.video_height == 0) + record_options.video_height = 1080; + if(record_options.record_area_width < 32) { record_options.record_area_width = 32; area_width_entry_ptr->set_text("32"); @@ -818,6 +902,16 @@ namespace gsr { area_height_entry_ptr->set_text("32"); } + if(record_options.video_width < 32) { + record_options.video_width = 32; + video_width_entry_ptr->set_text("32"); + } + + if(record_options.video_height < 32) { + record_options.video_height = 32; + video_height_entry_ptr->set_text("32"); + } + if(record_options.fps < 1) { record_options.fps = 1; framerate_entry_ptr->set_text("1"); |