creating_movies.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. .. _doc_creating_movies:
  2. Creating movies
  3. ===============
  4. Godot can record **non-real-time** video and audio from any 2D or 3D project.
  5. This kind of recording is also called *offline rendering*.
  6. There are many scenarios where this is useful:
  7. - Recording game trailers for promotional use.
  8. - Recording cutscenes that will be :ref:`displayed as pre-recorded videos <doc_playing_videos>`
  9. in the final game. This allows for using higher quality settings
  10. (at the cost of file size), regardless of the player's hardware.
  11. - Recording procedurally generated animations or motion design. User interaction
  12. remains possible during video recording, and audio can be included as well
  13. (although you won't be able to hear it while the video is recording).
  14. - Comparing the visual output of graphics settings, shaders, or rendering techniques
  15. in an animated scene.
  16. With Godot's animation features such as the AnimationPlayer node, Tweeners,
  17. particles and shaders, it can effectively be used to create any kind of 2D and
  18. 3D animations (and still images).
  19. If you are already used to Godot's workflow, you may find yourself more
  20. productive by using Godot for video rendering compared to Blender. That said,
  21. renderers designed for non-real-time usage such as Cycles and Eevee can result
  22. in better visuals (at the cost of longer rendering times).
  23. Compared to real-time video recording, some advantages of non-real-time recording include:
  24. - Use any graphics settings (including extremely demanding settings) regardless
  25. of your hardware's capabilities. The output video will *always* have perfect
  26. frame pacing; it will never exhibit dropped frames or stuttering.
  27. Faster hardware will allow you to render a given animation in less time, but
  28. the visual output remains identical.
  29. - Render at a higher resolution than the screen resolution, without having to
  30. rely on driver-specific tools such as NVIDIA's Dynamic Super Resolution or
  31. AMD's Virtual Super Resolution.
  32. - Render at a higher framerate than the video's target framerate, then
  33. :ref:`post-process to generate high-quality motion blur <doc_creating_movies_motion_blur>`.
  34. This also makes effects that converge over several frames (such as temporal antialiasing,
  35. SDFGI and volumetric fog) look better.
  36. .. warning::
  37. **This feature is not designed for capturing real-time footage during gameplay.**
  38. Players should use something like `OBS Studio <https://obsproject.com/>`__ or
  39. `SimpleScreenRecorder <https://www.maartenbaert.be/simplescreenrecorder/>`__
  40. to record gameplay videos, as they do a much better job at intercepting the
  41. compositor than Godot can do using Vulkan or OpenGL natively.
  42. That said, if your game runs at near-real-time speeds when capturing,
  43. you can still use this feature (but it will lack audible sound playback,
  44. as sound is saved directly to the video file).
  45. Enabling Movie Maker mode
  46. -------------------------
  47. To enable Movie Maker mode, click the "movie reel" button in the top-right
  48. corner of the editor *before* running the project:
  49. .. image:: img/movie_maker_enable.png
  50. The icon turns red when Movie Maker mode is enabled. Movie Maker status is *not*
  51. persisted when the editor quits, so you must re-enable Movie Maker mode again
  52. after restarting the editor if needed.
  53. .. note::
  54. Toggling Movie Maker mode while running the project will not have any
  55. effect until the project is restarted.
  56. Before you can record video by running the project, you still need to configure
  57. the output file path. This path can be set for all scenes in the Project Settings:
  58. .. image:: img/movie_maker_project_settings.png
  59. Alternatively, you can set the output file path on a per-scene basis by adding a
  60. String metadata with the name ``movie_file`` to the scene's **root node**. This
  61. is only used when the main scene is set to the scene in question, or when
  62. running the scene directly by pressing :kbd:`F6` (:kbd:`Cmd + R` on macOS).
  63. .. image:: img/movie_maker_per_scene_metadata.png
  64. The path specified in the project settings or metadata can be either absolute,
  65. or relative to the project root.
  66. Once you've configured and enabled Movie Maker mode, it will be automatically used
  67. when running the project from the editor.
  68. Command line usage
  69. ^^^^^^^^^^^^^^^^^^
  70. Movie Maker can also be enabled from the :ref:`command line <doc_command_line_tutorial>`:
  71. ::
  72. godot --path /path/to/your_project --write-movie output.avi
  73. If the output path is relative, then it is **relative to the project folder**,
  74. not the current working directory. In the above example, the file will be
  75. written to ``/path/to/your_project/output.avi``. This behavior is similar to the
  76. ``--export`` command line argument.
  77. Since Movie Maker's output resolution is set by the viewport size, you can
  78. adjust the window size on startup to override it if the project uses the
  79. ``disabled`` or ``canvas_items`` :ref:`stretch mode <doc_multiple_resolutions>`:
  80. ::
  81. godot --path /path/to/your_project --write-movie output.avi --resolution 1280x720
  82. Note that the window size is clamped by your display's resolution. See
  83. :ref:`doc_creating_movies_recording_at_higher_resolution` if you need to record
  84. a video at a higher resolution than the screen resolution.
  85. The recording FPS can also be overridden on the command line,
  86. without having to edit the Project Settings:
  87. ::
  88. godot --path /path/to/your_project --write-movie output.avi --fixed-fps 30
  89. .. note::
  90. The ``--write-movie`` and ``--fixed-fps`` command line arguments are both available
  91. in exported projects. Movie Maker mode cannot be toggled while the project is running,
  92. but you can use the :ref:`OS.execute() <class_OS_method_execute>` method to
  93. run a second instance of the exported project that will record a video file.
  94. Choosing an output format
  95. -------------------------
  96. Output formats are provided by the :ref:`MovieWriter <class_MovieWriter>` class.
  97. Godot has 2 built-in :ref:`MovieWriters <class_MovieWriter>`, and more can be
  98. implemented by extensions:
  99. AVI (recommended)
  100. ^^^^^^^^^^^^^^^^^
  101. AVI container with MJPEG for video and uncompressed audio. Features lossy video
  102. compression, resulting in medium file sizes and fast encoding. The lossy
  103. compression quality can be adjusted by changing
  104. **Editor > Movie Writer > MJPEG Quality**.
  105. The resulting file can be viewed in most video players, but it must be converted
  106. to another format for viewing on the web or by Godot with the VideoStreamPlayer
  107. node. MJPEG does not support transparency. AVI output is currently limited to a
  108. file of 4 GB in size at most.
  109. To use AVI, specify a path to an ``.avi`` file to be created in the
  110. **Editor > Movie Writer > Movie File** project setting.
  111. PNG
  112. ^^^
  113. PNG image sequence for video and WAV for audio. Features lossless video
  114. compression, at the cost of large file sizes and slow encoding. This is designed
  115. to be
  116. :ref:`encoded to a video file with an external tool after recording <doc_creating_movies_converting_avi>`.
  117. Transparency is supported, but the root viewport **must** have its
  118. ``transparent_bg`` property set to ``true`` for transparency to be visible on
  119. the output image. This can be achieved by enabling the **Rendering > Transparent
  120. Background** advanced project setting. **Display > Window > Size > Transparent**
  121. and **Display > Window > Per Pixel Transparency > Enabled** can optionally be
  122. enabled to allow transparency to be previewed while recording the video, but
  123. they do not have to be enabled for the output image to contain transparency.
  124. To use PNG, specify a ``.png`` file to be created in the
  125. **Editor > Movie Writer > Movie File** project setting. The generated ``.wav``
  126. file will have the same name as the ``.png`` file (minus the extension).
  127. Custom
  128. ^^^^^^
  129. If you need to encode directly to a different format or pipe a stream through
  130. third-party software, you can extend the MovieWriter class to create your own
  131. movie writers. This should typically be done using GDExtension for performance
  132. reasons.
  133. Configuration
  134. -------------
  135. In the **Editor > Movie Writer** section of the Project Settings, there are
  136. several options you can configure. Some of them are only visible after enabling
  137. the **Advanced** toggle in the top-right corner of the Project Settings dialog.
  138. - **Mix Rate Hz:** The audio mix rate to use in the recorded audio when writing
  139. a movie. This can be different from the project's mix rate, but this
  140. value must be divisible by the recorded FPS to prevent audio from
  141. desynchronizing over time.
  142. - **Speaker Mode:** The speaker mode to use in the recorded audio when writing
  143. a movie (stereo, 5.1 surround or 7.1 surround).
  144. - **MJPEG Quality:** The JPEG quality to use when writing a video to an AVI
  145. file, between ``0.01`` and ``1.0`` (inclusive). Higher quality values result
  146. in better-looking output at the cost of larger file sizes. Recommended quality
  147. values are between ``0.75`` and ``0.9``. Even at quality ``1.0``, JPEG
  148. compression remains lossy. This setting does not affect audio quality and is
  149. ignored when writing to a PNG image sequence.
  150. - **Movie File:** The output path for the movie. This can be absolute or
  151. relative to the project root.
  152. - **Disable V-Sync:** If enabled, requests V-Sync to be disabled when writing a
  153. movie. This can speed up video writing if the hardware is fast enough to
  154. render, encode and save the video at a framerate higher than the monitor's
  155. refresh rate. This setting has no effect if the operating system or graphics
  156. driver forces V-Sync with no way for applications to disable it.
  157. - **FPS:** The rendered frames per second in the output movie. Higher values
  158. result in smoother animation, at the cost of longer rendering times and larger
  159. output file sizes. Most video hosting platforms do not support FPS values
  160. higher than 60, but you can use a higher value and use that to generate motion
  161. blur.
  162. .. note::
  163. When using the ``disabled`` or ``2d`` :ref:`stretch modes <doc_multiple_resolutions>`,
  164. the output file's resolution is set by the window size. Make sure to resize
  165. the window *before* the splash screen has ended. For this purpose, it's
  166. recommended to adjust the
  167. **Display > Window > Size > Window Width Override** and
  168. **Window Height Override** advanced project settings.
  169. See also :ref:`doc_creating_movies_recording_at_higher_resolution`.
  170. Quitting Movie Maker mode
  171. -------------------------
  172. To safely quit a project that is using Movie Maker mode, use the X button at the
  173. top of the window, or call ``get_tree().quit()`` in a script.
  174. Pressing :kbd:`F8` (:kbd:`Cmd + .` on macOS) or pressing :kbd:`Ctrl + C` on the
  175. terminal running Godot is **not recommended**, as it will result in an
  176. improperly formatted AVI file with no duration information. For PNG image
  177. sequences, PNG images will not be negatively altered, but the associated WAV file
  178. will still lack duration information.
  179. Some video players may still be able to play the AVI or WAV file with working
  180. video and audio. However, software that makes use of the AVI or WAV file such as
  181. video editors may not be able to open the file.
  182. :ref:`Using a video converter program <doc_creating_movies_converting_avi>`
  183. can help in those cases.
  184. If you're using an AnimationPlayer to control a "main action" in the scene (such
  185. as camera movement), you can enable the **Movie Quit On Finish** property on the
  186. AnimationPlayer node in question. When enabled, this property will make Godot
  187. quit on its own when an animation is done playing *and* the engine is running in
  188. Movie Maker mode. Note that *this property has no effect on looping animations*.
  189. Therefore, you need to make sure that the animation is set as non-looping.
  190. Using high-quality graphics settings
  191. ------------------------------------
  192. The ``movie`` :ref:`feature tag <doc_feature_tags>` can be used to override
  193. specific project settings. This is useful to enable high-quality graphics settings
  194. that wouldn't be fast enough to run in real-time speeds on your hardware.
  195. Remember that putting every setting to its maximum value can still slow down
  196. movie saving speed, especially when recording at higher resolutions. Therefore,
  197. it's still recommended to only increase graphics settings if they make a meaningful
  198. difference in the output image.
  199. This feature tag can also be queried in a script to increase quality settings
  200. that are set in the Environment resource. For example, to further improve SDFGI
  201. detail and reduce light leaking:
  202. ::
  203. extends Node3D
  204. func _ready():
  205. if OS.has_feature("movie"):
  206. # When recording a movie, improve SDFGI cell density
  207. # without decreasing its maximum distance.
  208. get_viewport().world_3d.environment.sdfgi_min_cell_size *= 0.25
  209. get_viewport().world_3d.environment.sdfgi_cascades = 8
  210. .. _doc_creating_movies_recording_at_higher_resolution:
  211. Rendering at a higher resolution than the screen resolution
  212. -----------------------------------------------------------
  213. The overall rendering quality can be improved significantly by rendering at high
  214. resolutions such as 4K or 8K.
  215. .. note::
  216. For 3D rendering, Godot provides a **Rendering > Scaling 3D > Scale**
  217. advanced project setting, which can be set above ``1.0`` to obtain
  218. *supersample antialiasing*. The 3D rendering is then *downsampled* when it's
  219. drawn on the viewport. This provides an expensive but high-quality form of
  220. antialiasing, without increasing the final output resolution.
  221. Consider using this project setting first, as it avoids slowing down movie
  222. writing speeds and increasing output file size compared to actually
  223. increasing the output resolution.
  224. If you wish to render 2D at a higher resolution, or if you actually need the
  225. higher raw pixel output for 3D rendering, you can increase the resolution above
  226. what the screen allows.
  227. By default, Godot uses the ``disabled`` :ref:`stretch modes <doc_multiple_resolutions>`
  228. in projects. If using ``disabled`` or ``canvas_items`` stretch mode,
  229. the window size dictates the output video resolution.
  230. On the other hand, if the project is configured to use the ``viewport`` stretch
  231. mode, the viewport resolution dictates the output video resolution. The viewport
  232. resolution is set using the **Display > Window > Size > Viewport Width** and
  233. **Viewport Height** project settings. This can be used to render a video at a
  234. higher resolution than the screen resolution.
  235. To make the window smaller during recording without affecting the output video
  236. resolution, you can set the **Display > Window > Size > Window Width Override**
  237. and **Window Height Override** advanced project settings to values greater than
  238. ``0``.
  239. To apply a resolution override only when recording a movie, you can override
  240. those settings with the ``movie`` :ref:`feature tag <doc_feature_tags>`.
  241. Post-processing steps
  242. ---------------------
  243. Some common post-processing steps are listed below.
  244. .. note::
  245. When using several post-processing steps, try to perform all of them in a
  246. single FFmpeg command. This will save encoding time and improve quality by
  247. avoiding multiple lossy encoding steps.
  248. .. _doc_creating_movies_converting_avi:
  249. Converting AVI video to MP4
  250. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  251. While some platforms such as YouTube support uploading the AVI file directly, many
  252. others will require a conversion step beforehand. `HandBrake <https://handbrake.fr/>`__
  253. (GUI) and `FFmpeg <https://ffmpeg.org/>`__ (CLI) are popular open source tools
  254. for this purpose. FFmpeg has a steeper learning curve, but it's more powerful.
  255. The command below converts an AVI video to a MP4 (H.264) video with a Constant
  256. Rate Factor (CRF) of 15. This results in a relatively large file, but is
  257. well-suited for platforms that will re-encode your videos to reduce their size
  258. (such as most video sharing websites):
  259. ::
  260. ffmpeg -i input.avi -crf 15 output.mp4
  261. To get a smaller file at the cost of quality, *increase* the CRF value in the
  262. above command.
  263. To get a file with a better size/quality ratio (at the cost of slower encoding
  264. times), add ``-preset veryslow`` before ``-crf 15`` in the above command. On the
  265. contrary, ``-preset veryfast`` can be used to achieve faster encoding at the
  266. cost of a worse size/quality ratio.
  267. .. _doc_creating_movies_converting_image_sequence:
  268. Converting PNG image sequence + WAV audio to a video
  269. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  270. If you chose to record a PNG image sequence with a WAV file beside it,
  271. you need to convert it to a video before you can use it elsewhere.
  272. The filename for the PNG image sequence generated by Godot always contains 8
  273. digits, starting at 0 with zero-padded numbers. If you specify an output
  274. path ``folder/example.png``, Godot will write ``folder/example00000000.png``,
  275. ``folder/example00000001.png``, and so on in that folder. The audio will be saved
  276. at ``folder/example.wav``.
  277. The FPS is specified using the ``-r`` argument. It should match the FPS
  278. specified during recording. Otherwise, the video will appear to be slowed down
  279. or sped up, and audio will be out of sync with the video.
  280. ::
  281. ffmpeg -r 60 -i input%08d.png -i input.wav -crf 15 output.mp4
  282. If you recorded a PNG image sequence with transparency enabled, you need to use
  283. a video format that supports storing transparency. MP4/H.264 doesn't support
  284. storing transparency, so you can use WebM/VP9 as an alternative:
  285. ::
  286. ffmpeg -r 60 -i input%08d.png -i input.wav -c:v libvpx-vp9 -crf 15 -pix_fmt yuva420p output.webm
  287. .. _doc_creating_movies_motion_blur:
  288. Cutting video
  289. ^^^^^^^^^^^^^
  290. You can trim parts of the video you don't want to keep after the video is
  291. recorded. For example, to discard everything before 12.1 seconds and keep
  292. only 5.2 seconds of video after that point:
  293. ::
  294. ffmpeg -i input.avi -ss 00:00:12.10 -t 00:00:05.20 -crf 15 output.mp4
  295. Cutting videos can also be done with the GUI tool
  296. `LosslessCut <https://mifi.github.io/lossless-cut/>`__.
  297. Resizing video
  298. ^^^^^^^^^^^^^^
  299. The following command resizes a video to be 1080 pixels tall (1080p),
  300. while preserving its existing aspect ratio:
  301. ::
  302. ffmpeg -i input.avi -vf "scale=-1:1080" -crf 15 output.mp4
  303. .. _doc_creating_movies_reducing_framerate:
  304. Reducing framerate
  305. ^^^^^^^^^^^^^^^^^^
  306. The following command changes a video's framerate to 30 FPS, dropping some of
  307. the original frames if there are more in the input video:
  308. ::
  309. ffmpeg -i input.avi -r 30 -crf 15 output.mp4
  310. Generating accumulation motion blur with FFmpeg
  311. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  312. Godot does not have built-in support for motion blur, but it can still be
  313. created in recorded videos.
  314. If you record the video at a multiple of the original framerate, you can blend
  315. the frames together then reduce the frameate to produce a video with
  316. *accumulation motion blur*. This motion blur can look very good, but it can take
  317. a long time to generate since you have to render many more frames per second (on
  318. top of the time spent on post-processing).
  319. Example with a 240 FPS source video, generating 4× motion blur and decreasing
  320. its output framerate to 60 FPS:
  321. ::
  322. ffmpeg -i input.avi -vf "tmix=frames=4, fps=60" -crf 15 output.mp4
  323. This also makes effects that converge over several frames (such as temporal
  324. antialiasing, SDFGI and volumetric fog) converge faster and therefore look
  325. better, since they'll be able to work with more data at a given time.
  326. See :ref:`doc_creating_movies_reducing_framerate` if you want to get this benefit
  327. without adding motion blur.