Video encoding

From FlightGear wiki
Jump to navigation Jump to search

Overview

Flightgear 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.
  • Encoding performance can be improved by changing OSG's default thread-cpu affinity behaviour; see ThreadCPUAffinities.

Building

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.

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 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: https://op59.net/fgvideo-harrier-gr3-20211206-230342-manhattan.mp4