summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-06-17 00:55:19 +0200
committerreduz <reduzio@gmail.com>2022-06-21 11:28:47 +0200
commit5786516d4d6b517e6a28aec191f944aecf2f544d (patch)
tree8a79324296035a7aa8b7802d610596912b7c1642 /main
parent362f53ff02c381ea94640baa16e84e6f6956efef (diff)
Implement Running Godot as Movie Writer
* Allows running the game in "movie writer" mode. * It ensures entirely stable framerate, so your run can be saved stable and with proper sound (which is impossible if your CPU/GPU can't sustain doing this in real-time). * If disabling vsync, it can save movies faster than the game is run, but if you want to control the interaction it can get difficult. * Implements a simple, default MJPEG writer. This new features has two main use cases, which have high demand: * Saving game videos in high quality and ensuring the frame rate is *completely* stable, always. * Using Godot as a tool to make movies and animations (which is ideal if you want interaction, or creating them procedurally. No other software is as good for this). **Note**: This feature **IS NOT** for capturing real-time footage. Use something like OBS, SimpleScreenRecorder or FRAPS to achieve that, as they do a much better job at intercepting the compositor than Godot can probably do using Vulkan or OpenGL natively. If your game runs near real-time when capturing, you can still use this feature but it will play no sound (sound will be saved directly). Usage: $ godot --write-movie movie.avi [scene_file.tscn] Missing: * Options for configuring video writing via GLOBAL_DEF * UI Menu for launching with this mode from the editor. * Add to list of command line options. * Add a feature tag to override configurations when movie writing (fantastic for saving videos with highest quality settings).
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 50add16f3d..bfb0eacdfc 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -65,6 +65,8 @@
#include "servers/audio_server.h"
#include "servers/camera_server.h"
#include "servers/display_server.h"
+#include "servers/movie_writer/movie_writer.h"
+#include "servers/movie_writer/movie_writer_mjpeg.h"
#include "servers/navigation_server_2d.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
@@ -178,6 +180,9 @@ static bool debug_navigation = false;
static int frame_delay = 0;
static bool disable_render_loop = false;
static int fixed_fps = -1;
+static String write_movie_path;
+static MovieWriter *movie_writer = nullptr;
+static bool disable_vsync = false;
static bool print_fps = false;
#ifdef TOOLS_ENABLED
static bool dump_extension_api = false;
@@ -325,6 +330,8 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --text-driver <driver> Text driver (Fonts, BiDi, shaping)\n");
OS::get_singleton()->print(" --tablet-driver <driver> Pen tablet input driver.\n");
OS::get_singleton()->print(" --headless Enable headless mode (--display-driver headless --audio-driver Dummy). Useful for servers and with --script.\n");
+ OS::get_singleton()->print(" --write-movie <file> Run the engine in a way that a movie is written (by default .avi MJPEG). Fixed FPS is forced when enabled, but can be used to change movie FPS. Disabling vsync can speed up movie writing but makes interaction more difficult.\n");
+ OS::get_singleton()->print(" --disable-vsync Force disabling of vsync. Run the engine in a way that a movie is written (by default .avi MJPEG). Fixed FPS is forced when enabled, but can be used to change movie FPS.\n");
OS::get_singleton()->print("\n");
@@ -1136,6 +1143,20 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing fixed-fps argument, aborting.\n");
goto error;
}
+ } else if (I->get() == "--write-movie") {
+ if (I->next()) {
+ write_movie_path = I->next()->get();
+ N = I->next()->next();
+ if (fixed_fps == -1) {
+ fixed_fps = 60;
+ }
+ OS::get_singleton()->_writing_movie = true;
+ } else {
+ OS::get_singleton()->print("Missing write-movie argument, aborting.\n");
+ goto error;
+ }
+ } else if (I->get() == "--disable-vsync") {
+ disable_vsync = true;
} else if (I->get() == "--print-fps") {
print_fps = true;
} else if (I->get() == "--profile-gpu") {
@@ -1462,7 +1483,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
if (audio_driver_idx < 0) {
- audio_driver_idx = 0;
+ audio_driver_idx = 0; // 0 Is always available as the dummy driver (no sound)
+ }
+
+ if (write_movie_path != String()) {
+ // Always use dummy driver for audio driver (which is last), also in no threaded mode.
+ audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
+ AudioDriverDummy::get_dummy_singleton()->set_use_threads(false);
}
{
@@ -1470,6 +1497,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
{
window_vsync_mode = DisplayServer::VSyncMode(int(GLOBAL_DEF("display/window/vsync/vsync_mode", DisplayServer::VSyncMode::VSYNC_ENABLED)));
+ if (disable_vsync) {
+ window_vsync_mode = DisplayServer::VSyncMode::VSYNC_DISABLED;
+ }
}
Engine::get_singleton()->set_physics_ticks_per_second(GLOBAL_DEF_BASIC("physics/common/physics_ticks_per_second", 60));
ProjectSettings::get_singleton()->set_custom_property_info("physics/common/physics_ticks_per_second",
@@ -1553,6 +1583,7 @@ error:
display_driver = "";
audio_driver = "";
tablet_driver = "";
+ write_movie_path = "";
project_path = "";
args.clear();
@@ -1725,6 +1756,14 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
rendering_server->set_print_gpu_profile(true);
}
+ if (write_movie_path != String()) {
+ movie_writer = MovieWriter::find_writer_for_file(write_movie_path);
+ if (movie_writer == nullptr) {
+ ERR_PRINT("Can't find movie writer for file type, aborting: " + write_movie_path);
+ write_movie_path = String();
+ }
+ }
+
#ifdef UNIX_ENABLED
// Print warning after initializing the renderer but before initializing audio.
if (OS::get_singleton()->get_environment("USER") == "root" && !OS::get_singleton()->has_environment("GODOT_SILENCE_ROOT_WARNING")) {
@@ -2650,6 +2689,9 @@ bool Main::start() {
OS::get_singleton()->set_main_loop(main_loop);
+ if (movie_writer) {
+ movie_writer->begin(DisplayServer::get_singleton()->window_get_size(), fixed_fps, write_movie_path);
+ }
return true;
}
@@ -2836,6 +2878,13 @@ bool Main::iteration() {
Input::get_singleton()->flush_buffered_events();
}
+ if (movie_writer) {
+ RID main_vp_rid = RenderingServer::get_singleton()->viewport_find_from_screen_attachment(DisplayServer::MAIN_WINDOW_ID);
+ RID main_vp_texture = RenderingServer::get_singleton()->viewport_get_texture(main_vp_rid);
+ Ref<Image> vp_tex = RenderingServer::get_singleton()->texture_2d_get(main_vp_texture);
+ movie_writer->add_frame(vp_tex);
+ }
+
if (fixed_fps != -1) {
return exit;
}
@@ -2875,6 +2924,10 @@ void Main::cleanup(bool p_force) {
ERR_FAIL_COND(!_start_success);
}
+ if (movie_writer) {
+ movie_writer->end();
+ }
+
ResourceLoader::remove_custom_loaders();
ResourceSaver::remove_custom_savers();