Skip to content

Commit 2a2f84d

Browse files
committed
Add project settings for Theora encoding
1 parent 2de35f4 commit 2a2f84d

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

doc/classes/MovieWriter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<description>
77
Godot can record videos with non-real-time simulation. Like the [code]--fixed-fps[/code] [url=$DOCS_URL/tutorials/editor/command_line_tutorial.html]command line argument[/url], this forces the reported [code]delta[/code] in [method Node._process] functions to be identical across frames, regardless of how long it actually took to render the frame. This can be used to record high-quality videos with perfect frame pacing regardless of your hardware's capabilities.
88
Godot has 3 built-in [MovieWriter]s:
9-
- OGV container with Theora for video and Vorbis for audio ([code].ogv[/code] file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing [member ProjectSettings.editor/movie_writer/video_quality] and [member ProjectSettings.editor/movie_writer/audio_quality]. The resulting file can be viewed in Godot with [VideoStreamPlayer] and most video players, but not web browsers as they don't support Theora.
9+
- OGV container with Theora for video and Vorbis for audio ([code].ogv[/code] file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing [member ProjectSettings.editor/movie_writer/video_quality] and [member ProjectSettings.editor/movie_writer/ogv/audio_quality]. The resulting file can be viewed in Godot with [VideoStreamPlayer] and most video players, but not web browsers as they don't support Theora.
1010
- AVI container with MJPEG for video and uncompressed audio ([code].avi[/code] file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing [member ProjectSettings.editor/movie_writer/video_quality]. The resulting file can be viewed in most video players, but it must be converted to another format for viewing on the web or by Godot with [VideoStreamPlayer]. MJPEG does not support transparency. AVI output is currently limited to a file of 4 GB in size at most.
1111
- PNG image sequence for video and WAV for audio ([code].png[/code] file extension). Lossless compression, large file sizes, slow encoding. Designed to be encoded to a video file with another tool such as [url=https://ffmpeg.org/]FFmpeg[/url] after recording. Transparency is currently not supported, even if the root viewport is set to be transparent.
1212
If you need to encode to a different format or pipe a stream through third-party software, you can extend the [MovieWriter] class to create your own movie writers. This should typically be done using GDExtension for performance reasons.

doc/classes/ProjectSettings.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,6 @@
10941094
<member name="editor/import/use_multiple_threads" type="bool" setter="" getter="" default="true">
10951095
If [code]true[/code] importing of resources is run on multiple threads.
10961096
</member>
1097-
<member name="editor/movie_writer/audio_quality" type="float" setter="" getter="" default="0.5">
1098-
The audio encoding quality to use when writing Theora (Ogg Vorbis) audio to a file, between [code]0.0[/code] and [code]1.0[/code] (inclusive). Higher [code]quality[/code] values result in better-sounding output at the cost of larger file sizes. Even at quality [code]1.0[/code], compression remains lossy.
1099-
[b]Note:[/b] This does not affect video quality.
1100-
</member>
11011097
<member name="editor/movie_writer/disable_vsync" type="bool" setter="" getter="" default="false">
11021098
If [code]true[/code], requests V-Sync to be disabled when writing a movie (similar to setting [member display/window/vsync/vsync_mode] to [b]Disabled[/b]). This can speed up video writing if the hardware is fast enough to render, encode and save the video at a framerate higher than the monitor's refresh rate.
11031099
[b]Note:[/b] [member editor/movie_writer/disable_vsync] has no effect if the operating system or graphics driver forces V-Sync with no way for applications to disable it.
@@ -1112,12 +1108,25 @@
11121108
<member name="editor/movie_writer/movie_file" type="String" setter="" getter="" default="&quot;&quot;">
11131109
The output path for the movie. The file extension determines the [MovieWriter] that will be used.
11141110
Godot has 3 built-in [MovieWriter]s:
1115-
- OGV container with Theora for video and Vorbis for audio ([code].ogv[/code] file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing [member ProjectSettings.editor/movie_writer/video_quality] and [member ProjectSettings.editor/movie_writer/audio_quality]. The resulting file can be viewed in Godot with [VideoStreamPlayer] and most video players, but not web browsers as they don't support Theora.
1111+
- OGV container with Theora for video and Vorbis for audio ([code].ogv[/code] file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing [member ProjectSettings.editor/movie_writer/video_quality] and [member ProjectSettings.editor/movie_writer/ogv/audio_quality]. The resulting file can be viewed in Godot with [VideoStreamPlayer] and most video players, but not web browsers as they don't support Theora.
11161112
- AVI container with MJPEG for video and uncompressed audio ([code].avi[/code] file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing [member ProjectSettings.editor/movie_writer/video_quality]. The resulting file can be viewed in most video players, but it must be converted to another format for viewing on the web or by Godot with [VideoStreamPlayer]. MJPEG does not support transparency. AVI output is currently limited to a file of 4 GB in size at most.
11171113
- PNG image sequence for video and WAV for audio ([code].png[/code] file extension). Lossless compression, large file sizes, slow encoding. Designed to be encoded to a video file with another tool such as [url=https://ffmpeg.org/]FFmpeg[/url] after recording. Transparency is currently not supported, even if the root viewport is set to be transparent.
11181114
If you need to encode to a different format or pipe a stream through third-party software, you can extend this [MovieWriter] class to create your own movie writers.
11191115
When using PNG output, the frame number will be appended at the end of the file name. It starts from 0 and is padded with 8 digits to ensure correct sorting and easier processing. For example, if the output path is [code]/tmp/hello.png[/code], the first two frames will be [code]/tmp/hello00000000.png[/code] and [code]/tmp/hello00000001.png[/code]. The audio will be saved at [code]/tmp/hello.wav[/code].
11201116
</member>
1117+
<member name="editor/movie_writer/ogv/audio_quality" type="float" setter="" getter="" default="0.2">
1118+
The audio encoding quality to use when writing Vorbis audio to a file, between [code]-0.1[/code] and [code]1.0[/code] (inclusive). Higher [code]quality[/code] values result in better-sounding output at the cost of larger file sizes. Even at quality [code]1.0[/code], compression remains lossy.
1119+
[b]Note:[/b] This does not affect video quality.
1120+
</member>
1121+
<member name="editor/movie_writer/ogv/encoding_speed" type="int" setter="" getter="" default="3">
1122+
Trades speed for compression. Speed [code]1[/code] is the slowest but provides the best compression. Speed [code]4[/code] is the fastest but provides the worst compression.
1123+
</member>
1124+
<member name="editor/movie_writer/ogv/keyframe_interval" type="int" setter="" getter="" default="64">
1125+
Forces keyframes at the specified interval. Higher values can improve compression up to a certain level at the expense of some seek latency.
1126+
</member>
1127+
<member name="editor/movie_writer/ogv/video_bitrate" type="int" setter="" getter="" default="0">
1128+
When greater than [code]0[/code] CBR is used instead of VBR and sets the target bitrate for the video encoder in KB. The higher the value the better video quality and bigger file size. VBR should give better results and it's thus recommended to leave this value at [code]0[/code].
1129+
</member>
11211130
<member name="editor/movie_writer/speaker_mode" type="int" setter="" getter="" default="0">
11221131
The speaker mode to use in the recorded audio when writing a movie. See [enum AudioServer.SpeakerMode] for possible values.
11231132
</member>

modules/theora/movie_writer_ogv.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Error MovieWriterOGV::write_begin(const Size2i &p_movie_size, uint32_t p_fps, co
191191
// Account for the Ogg page overhead.
192192
// This is 1 byte per 255 for lacing values, plus 26 bytes per 4096 bytes for
193193
// the page header, plus approximately 1/2 byte per packet (not accounted for here).
194-
//ti.target_bitrate = (int)(64870 * (ogg_int64_t)video_bitrate >> 16);
194+
ti.target_bitrate = (int)(64870 * (ogg_int64_t)video_bitrate >> 16);
195195
ti.quality = video_quality * 63;
196196
ti.pixel_fmt = TH_PF_420;
197197
td = th_encode_alloc(&ti);
@@ -419,5 +419,8 @@ MovieWriterOGV::MovieWriterOGV() {
419419
mix_rate = GLOBAL_GET("editor/movie_writer/mix_rate");
420420
speaker_mode = AudioServer::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));
421421
video_quality = GLOBAL_GET("editor/movie_writer/video_quality");
422-
audio_quality = GLOBAL_GET("editor/movie_writer/audio_quality");
422+
audio_quality = GLOBAL_GET("editor/movie_writer/ogv/audio_quality");
423+
speed = 1 + (int)GLOBAL_GET("editor/movie_writer/ogv/encoding_speed");
424+
video_bitrate = 1000 * (int)GLOBAL_GET("editor/movie_writer/ogv/video_bitrate");
425+
keyframe_frequency = GLOBAL_GET("editor/movie_writer/ogv/keyframe_interval");
423426
}

servers/movie_writer/movie_writer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ void MovieWriter::_bind_methods() {
156156
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/movie_writer/mix_rate", PROPERTY_HINT_RANGE, "8000,192000,1,suffix:Hz"), 48000);
157157
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/movie_writer/speaker_mode", PROPERTY_HINT_ENUM, "Stereo,3.1,5.1,7.1"), 0);
158158
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "editor/movie_writer/video_quality", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), 0.75);
159-
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "editor/movie_writer/audio_quality", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), 0.5);
159+
GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "editor/movie_writer/ogv/audio_quality", PROPERTY_HINT_RANGE, "-0.1,1.0,0.01"), 0.2);
160+
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/movie_writer/ogv/encoding_speed", PROPERTY_HINT_ENUM, "1,2,3,4"), 3);
161+
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/movie_writer/ogv/keyframe_interval", PROPERTY_HINT_RANGE, "1,1024,1"), 64);
162+
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/movie_writer/ogv/video_bitrate", PROPERTY_HINT_RANGE, "0,100000,1000"), 0);
160163

161164
// Used by the editor.
162165
GLOBAL_DEF_BASIC("editor/movie_writer/movie_file", "");

0 commit comments

Comments
 (0)