creating_movies.rst 20 KB

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