Video encoding

From FlightGear wiki
Jump to navigation Jump to search


Flightgear on next (the development branch) has support for video encoding of the main window. This requires that ffmpeg/libav libraries are available at build time.

  • Videos are generated in the current directory. This can be changed by setting property /sim/video/directory.
  • Video files are called fgvideo-<aircraft>-YYYYMMDD-HHMMSS.<container>, for example fgvideo-harrier-gr3-20211209-234105.mp4.
  • A convenience link is created that points to the latest video, called fgvideo-<aircraft>.<container>, for example fgvideo-harrier-gr3.mp4 -> fgvideo-harrier-gr3-20211209-234105.mp4.


  • As of 2021-12-12, only Unix builds of Flightgear include support for video encoding by default.
    • On other platforms, if ffmpeg libraries are installed on the system, Flightgear's cmake might pick them up automatically and enable video encoding, but this hasn't been tested.
  • We do not (yet) record sound.


On Unix, we require these libraries and their header files to be available at build time:

  • avcodec
  • avutil
  • swscale
  • avformat

If these libraries and header files are installed, a standard cmake build should automatically include video encoding support.

As of 2021-12-27, installs these libraries automatically.

On Devuan (and probably other Debian-based distributions), they can be manually installed with:

   sudo apt install libavcodec-dev libavutil-dev libswscale-dev libavformat-dev

Creating video of live Flightgear

Starting/stopping video encoding

Use menu items File/Video Start and File/Video Stop to start/stop video encoding.

  • If an error occurs, for example support for video encoding was not included at build time, Flightgear will show a popup warning message.

Video encoding settings

Video-control dialogue.png

Menu File/Video Control opens a dialogue that allows control over various settings, including:

  • Container name, such as mp4 or ogv.
    • Radio buttons are provided for common containers.
    • Run ffmpeg -formats in a separate terminal to see what containers are available on your system.
  • Codec name, such as mpeg2video, libx264, libx265.
    • Radio buttons are provided for common codecs.
    • Run ffmpeg -codecs in a separate terminal to see what codecs are available on your system.
  • Encoding quality in range 0..1. Use -1 for codec's default.
  • Encoding speed in range 0..1. Use -1 for codec's default.
  • Encoding target bitrate in bits per second. Use 0 for codec's default.

Some combinations of container and codec are not supported by Ffmpeg, for example container OGV and codec H.265. If this happens, an error message will pop up; you can try again with different settings.

Creating video from Flightgear recordings

Flightgear can automatically generate a video when replaying a recording file, stopping video encoding when we reach the end of the recording.

Usually one would use a Continuous recording for this, as they contain full information regardless of the recording duration.

  • From within Flightgear:
    • In the Load Flight Recorder Tape dialogue, set the Auto-create video checkbox.
    • Optionally also set Fixed dt (see below).
  • With the command line --load-tape option:
    • Also specify --load-tape-create-video.
    • Optionally specify --load-tape-fixed-dt=... (see below).

Using fixed-dt

Setting fixed-dt to a non-zero value forces Flightgear to increment the FDM time in seconds by the specified amount each frame, instead of by the elapsed real-world time between frames. For example using a value of 0.04 will force a frame rate of 25fps.

This allows creation of high quality videos from recordings, regardless of the rendering settings or speed of the host, at the expense of potentially taking longer than real time to create the recording.

Command line examples

Create a high quality video of a recording by running Flightgear with these command-line args:

   --load-tape=... --load-tape-create-video=1 --prop:bool:/sim/time/simple-time/enabled=true --load-tape-fixed-dt=0.04 --graphics-preset=high-quality

Also fix video settings by setting the relevant properties:

   --load-tape=... --load-tape-create-video=1 --prop:bool:/sim/time/simple-time/enabled=true --load-tape-fixed-dt=0.04 --graphics-preset=high-quality --prop:/sim/video/container=mp4 --prop:/sim/video/codec=libx265 --prop:/sim/video/quality=0.75 --prop:/sim/video/speed=1

Example video

This 5 minute video flying around Manhattan with high rendering settings was created on a fairly slow laptop, taking about an hour to replay and encode: