creating_movies.rst 23 KB

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