Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
MovieWriter
繼承: Object
非即時影片錄製編碼器的抽象類別。
說明
Godot can record videos with non-real-time simulation. Like the --fixed-fps command line argument, this forces the reported delta in 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.
Godot has 3 built-in MovieWriters:
OGV container with Theora for video and Vorbis for audio (
.ogvfile extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing ProjectSettings.editor/movie_writer/video_quality and 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.AVI container with MJPEG for video and uncompressed audio (
.avifile extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing 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.PNG image sequence for video and WAV for audio (
.pngfile extension). Lossless compression, large file sizes, slow encoding. Designed to be encoded to a video file with another tool such as FFmpeg after recording. Transparency is currently not supported, even if the root viewport is set to be transparent.
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.
Editor usage: A default movie file path can be specified in ProjectSettings.editor/movie_writer/movie_file. Alternatively, for running single scenes, a movie_file metadata can be added to the root node, specifying the path to a movie file that will be used when recording that scene. Once a path is set, click the video reel icon in the top-right corner of the editor to enable Movie Maker mode, then run any scene as usual. The engine will start recording as soon as the splash screen is finished, and it will only stop recording when the engine quits. Click the video reel icon again to disable Movie Maker mode. Note that toggling Movie Maker mode does not affect project instances that are already running.
Note: MovieWriter is available for use in both the editor and exported projects, but it is not designed for use by end users to record videos while playing. Players wishing to record gameplay videos should install tools such as OBS Studio or SimpleScreenRecorder instead.
Note: MJPEG support (.avi file extension) depends on the jpg module being enabled at compile time (default behavior).
Note: OGV support (.ogv file extension) depends on the theora module being enabled at compile time (default behavior). Theora compression is only available in editor binaries.
方法
_get_audio_mix_rate() virtual required const |
|
_get_audio_speaker_mode() virtual required const |
|
_get_supported_extensions() virtual required const |
|
_handles_file(path: String) virtual required const |
|
_write_begin(movie_size: Vector2i, fps: int, base_path: String) virtual required |
|
void |
_write_end() virtual required |
_write_frame(frame_image: Image, audio_frame_block: |
|
void |
add_writer(writer: MovieWriter) static |
方法說明
int _get_audio_mix_rate() virtual required const 🔗
當引擎請求用於錄製音訊的音訊取樣速率時呼叫。返回的值必須以 Hz 為單位指定。如果 _get_audio_mix_rate() 未被重寫,則預設為 48000 Hz。
SpeakerMode _get_audio_speaker_mode() virtual required const 🔗
當引擎請求用於錄製音訊的音訊揚聲器模式時呼叫。這可能會影響生成的音訊檔/流中的輸出通道數。如果 _get_audio_speaker_mode() 未被重寫,則預設為 AudioServer.SPEAKER_MODE_STEREO。
PackedStringArray _get_supported_extensions() virtual required const 🔗
Returns the list of supported filename extensions for movies written with this MovieWriter.
bool _handles_file(path: String) virtual required const 🔗
當引擎確定該 MovieWriter 是否能夠處理位於 path 的檔時呼叫。如果該 MovieWriter 能夠處理給定的檔路徑,則必須返回 true,否則返回 false。通常,_handles_file() 如下被重寫,以允許使用者使用給定檔副檔名,在任何路徑下記錄一個檔:
func _handles_file(path):
# 允許指定一個帶有 `.mkv` 檔副檔名(不區分大小寫)的輸出檔,
# 在專案設定中或使用 `--write-movie <path>` 命令列參數。
return path.get_extension().to_lower() == "mkv"
Error _write_begin(movie_size: Vector2i, fps: int, base_path: String) virtual required 🔗
在引擎開始寫入影片和音訊資料之前呼叫一次。movie_size 是要保存的影片的寬度和高度。fps 是指定的每秒影格數,在專案設定中、或使用 --fixed-fps <fps>《命令列參數》指定。
void _write_end() virtual required 🔗
當引擎完成寫入時呼叫。當引擎通過按下視窗管理器的關閉按鈕退出時,或呼叫 SceneTree.quit() 時,會發生這種情況。
注意:在運作編輯器/專案的終端上,按 Ctrl + C,不會導致 _write_end() 被呼叫。
Error _write_frame(frame_image: Image, audio_frame_block: const void*) virtual required 🔗
在每個算繪的影格結束時被呼叫。應寫入 frame_image 和 audio_frame_block 函式參數。
void add_writer(writer: MovieWriter) static 🔗
新增一個可供引擎使用的編寫器。可以通過重寫 _handles_file(),來設定支援的檔案副檔名。
注意:add_writer() 必須在引擎初始化期間儘早呼叫才能工作,因為電影編寫被設計為與引擎的其餘部分同時啟動。