class_moviewriter.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/MovieWriter.xml.
  6. .. _class_MovieWriter:
  7. MovieWriter
  8. ===========
  9. **Inherits:** :ref:`Object<class_Object>`
  10. Abstract class for non-real-time video recording encoders.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Godot can record videos with non-real-time simulation. Like the ``--fixed-fps`` :doc:`command line argument <../tutorials/editor/command_line_tutorial>`, this forces the reported ``delta`` in :ref:`Node._process<class_Node_private_method__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.
  15. Godot has 2 built-in **MovieWriter**\ s:
  16. - AVI container with MJPEG for video and uncompressed audio (``.avi`` file extension). Lossy compression, medium file sizes, fast encoding. The lossy compression quality can be adjusted by changing :ref:`ProjectSettings.editor/movie_writer/mjpeg_quality<class_ProjectSettings_property_editor/movie_writer/mjpeg_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 :ref:`VideoStreamPlayer<class_VideoStreamPlayer>`. MJPEG does not support transparency. AVI output is currently limited to a file of 4 GB in size at most.
  17. - PNG image sequence for video and WAV for audio (``.png`` file extension). Lossless compression, large file sizes, slow encoding. Designed to be encoded to a video file with another tool such as `FFmpeg <https://ffmpeg.org/>`__ after recording. Transparency is currently not supported, even if the root viewport is set to be transparent.
  18. 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.
  19. \ **Editor usage:** A default movie file path can be specified in :ref:`ProjectSettings.editor/movie_writer/movie_file<class_ProjectSettings_property_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.
  20. \ **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 <https://obsproject.com/>`__ or `SimpleScreenRecorder <https://www.maartenbaert.be/simplescreenrecorder/>`__ instead.
  21. .. rst-class:: classref-reftable-group
  22. Methods
  23. -------
  24. .. table::
  25. :widths: auto
  26. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`int<class_int>` | :ref:`_get_audio_mix_rate<class_MovieWriter_private_method__get_audio_mix_rate>`\ (\ ) |virtual| |const| |
  28. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`SpeakerMode<enum_AudioServer_SpeakerMode>` | :ref:`_get_audio_speaker_mode<class_MovieWriter_private_method__get_audio_speaker_mode>`\ (\ ) |virtual| |const| |
  30. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`_handles_file<class_MovieWriter_private_method__handles_file>`\ (\ path\: :ref:`String<class_String>`\ ) |virtual| |const| |
  32. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`_write_begin<class_MovieWriter_private_method__write_begin>`\ (\ movie_size\: :ref:`Vector2i<class_Vector2i>`, fps\: :ref:`int<class_int>`, base_path\: :ref:`String<class_String>`\ ) |virtual| |
  34. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | |void| | :ref:`_write_end<class_MovieWriter_private_method__write_end>`\ (\ ) |virtual| |
  36. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`_write_frame<class_MovieWriter_private_method__write_frame>`\ (\ frame_image\: :ref:`Image<class_Image>`, audio_frame_block\: ``const void*``\ ) |virtual| |
  38. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | |void| | :ref:`add_writer<class_MovieWriter_method_add_writer>`\ (\ writer\: :ref:`MovieWriter<class_MovieWriter>`\ ) |static| |
  40. +--------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. .. rst-class:: classref-section-separator
  42. ----
  43. .. rst-class:: classref-descriptions-group
  44. Method Descriptions
  45. -------------------
  46. .. _class_MovieWriter_private_method__get_audio_mix_rate:
  47. .. rst-class:: classref-method
  48. :ref:`int<class_int>` **_get_audio_mix_rate**\ (\ ) |virtual| |const| :ref:`🔗<class_MovieWriter_private_method__get_audio_mix_rate>`
  49. Called when the audio sample rate used for recording the audio is requested by the engine. The value returned must be specified in Hz. Defaults to 48000 Hz if :ref:`_get_audio_mix_rate<class_MovieWriter_private_method__get_audio_mix_rate>` is not overridden.
  50. .. rst-class:: classref-item-separator
  51. ----
  52. .. _class_MovieWriter_private_method__get_audio_speaker_mode:
  53. .. rst-class:: classref-method
  54. :ref:`SpeakerMode<enum_AudioServer_SpeakerMode>` **_get_audio_speaker_mode**\ (\ ) |virtual| |const| :ref:`🔗<class_MovieWriter_private_method__get_audio_speaker_mode>`
  55. Called when the audio speaker mode used for recording the audio is requested by the engine. This can affect the number of output channels in the resulting audio file/stream. Defaults to :ref:`AudioServer.SPEAKER_MODE_STEREO<class_AudioServer_constant_SPEAKER_MODE_STEREO>` if :ref:`_get_audio_speaker_mode<class_MovieWriter_private_method__get_audio_speaker_mode>` is not overridden.
  56. .. rst-class:: classref-item-separator
  57. ----
  58. .. _class_MovieWriter_private_method__handles_file:
  59. .. rst-class:: classref-method
  60. :ref:`bool<class_bool>` **_handles_file**\ (\ path\: :ref:`String<class_String>`\ ) |virtual| |const| :ref:`🔗<class_MovieWriter_private_method__handles_file>`
  61. Called when the engine determines whether this **MovieWriter** is able to handle the file at ``path``. Must return ``true`` if this **MovieWriter** is able to handle the given file path, ``false`` otherwise. Typically, :ref:`_handles_file<class_MovieWriter_private_method__handles_file>` is overridden as follows to allow the user to record a file at any path with a given file extension:
  62. ::
  63. func _handles_file(path):
  64. # Allows specifying an output file with a `.mkv` file extension (case-insensitive),
  65. # either in the Project Settings or with the `--write-movie <path>` command line argument.
  66. return path.get_extension().to_lower() == "mkv"
  67. .. rst-class:: classref-item-separator
  68. ----
  69. .. _class_MovieWriter_private_method__write_begin:
  70. .. rst-class:: classref-method
  71. :ref:`Error<enum_@GlobalScope_Error>` **_write_begin**\ (\ movie_size\: :ref:`Vector2i<class_Vector2i>`, fps\: :ref:`int<class_int>`, base_path\: :ref:`String<class_String>`\ ) |virtual| :ref:`🔗<class_MovieWriter_private_method__write_begin>`
  72. Called once before the engine starts writing video and audio data. ``movie_size`` is the width and height of the video to save. ``fps`` is the number of frames per second specified in the project settings or using the ``--fixed-fps <fps>`` :doc:`command line argument <../tutorials/editor/command_line_tutorial>`.
  73. .. rst-class:: classref-item-separator
  74. ----
  75. .. _class_MovieWriter_private_method__write_end:
  76. .. rst-class:: classref-method
  77. |void| **_write_end**\ (\ ) |virtual| :ref:`🔗<class_MovieWriter_private_method__write_end>`
  78. Called when the engine finishes writing. This occurs when the engine quits by pressing the window manager's close button, or when :ref:`SceneTree.quit<class_SceneTree_method_quit>` is called.
  79. \ **Note:** Pressing :kbd:`Ctrl + C` on the terminal running the editor/project does *not* result in :ref:`_write_end<class_MovieWriter_private_method__write_end>` being called.
  80. .. rst-class:: classref-item-separator
  81. ----
  82. .. _class_MovieWriter_private_method__write_frame:
  83. .. rst-class:: classref-method
  84. :ref:`Error<enum_@GlobalScope_Error>` **_write_frame**\ (\ frame_image\: :ref:`Image<class_Image>`, audio_frame_block\: ``const void*``\ ) |virtual| :ref:`🔗<class_MovieWriter_private_method__write_frame>`
  85. Called at the end of every rendered frame. The ``frame_image`` and ``audio_frame_block`` function arguments should be written to.
  86. .. rst-class:: classref-item-separator
  87. ----
  88. .. _class_MovieWriter_method_add_writer:
  89. .. rst-class:: classref-method
  90. |void| **add_writer**\ (\ writer\: :ref:`MovieWriter<class_MovieWriter>`\ ) |static| :ref:`🔗<class_MovieWriter_method_add_writer>`
  91. Adds a writer to be usable by the engine. The supported file extensions can be set by overriding :ref:`_handles_file<class_MovieWriter_private_method__handles_file>`.
  92. \ **Note:** :ref:`add_writer<class_MovieWriter_method_add_writer>` must be called early enough in the engine initialization to work, as movie writing is designed to start at the same time as the rest of the engine.
  93. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  94. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  95. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  96. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  97. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  98. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  99. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  100. .. |void| replace:: :abbr:`void (No return value.)`