FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Screenshots, videos and camera control

This page covers practical ways to capture visual output when running FhVis.

1) Capture screenshots from visualization

Add a <FileRenderer> observer to the <OBSERVERS> section and run with FhVis. One frame at time 15 s:

<OBSERVERS>
<FileRenderer fps="1" startTime="15" stopTime="15"
width="1920" height="1080" outputFolder="shots" outputFile="shot.png"/>
</OBSERVERS>

The picture shows the state at exactly 15 s, interpolated between the two solver steps around it. It has the size you give, whatever the window size, and it shows the scene only, without the Hud. outputFile needs one integer field, so a single shot is best named shot_%05d.png. The frame count is the file number: the first file is shot_00000.png.

2) Record image sequences and encode video

To export frames from 15 s to 100 s at 24 frames per simulation second:

<OBSERVERS>
<FileOutput outputFile="results.csv" Select="objects:all"/>
<FileRenderer fps="24" startTime="15" stopTime="100" outputFolder="frames"/>
</OBSERVERS>

The files are frames/frame_00000.png, frame_00001.png, and so on, with no gaps. Only the listed observers run, so list <FileOutput> if you also want a result file. <FileRenderer> replaces the old Camera/Shot SimObject. Do not list <Visualization> beside it: <FileRenderer> draws the window itself, and outside [startTime, stopTime] it draws one window frame per simulation second (fpsOutsideFileRenderWindow).

Let FhVis encode the video for you:

<FileRenderer fps="24" startTime="15" stopTime="100" output="ffmpeg" videoFile="video.mp4"/>

output="both" keeps the PNG files too, for example for annotation. ffmpeg must be on PATH, or set ffmpegExecutable. See FileRenderer for every attribute.

You can also encode the PNG files yourself:

ffmpeg -framerate 24 -i frames/frame_%05d.png -c:v libx264 -crf 20 -pix_fmt yuv420p video.mp4

Annotate the movie

Add <Overlays> inside <FileRenderer> to draw a logo and the simulation time on every frame:

<FileRenderer fps="24" startTime="15" stopTime="100" output="ffmpeg">
<Overlays>
<Image source="annotations/logo.png" width="12" position="NorthEast" margin="2"/>
<TimeStamp format="t = %.1f s" position="SouthWest" margin="2"/>
</Overlays>
</FileRenderer>

The image path is relative to the folder of the input file. Add start, duration and fade to an item to show it only for a while. See Overlays for every attribute.

For a richer annotation, write a LaTeX .tex file and let fhsim_video make the PNG: python3 fhsim_video.py TEX. The PNG lands next to the .tex file. Then name that PNG in an <Image> item.

Tips:

  • Lower crf gives better quality and larger files.
  • For presentation software compatibility, you may need bitrate-based encoding:
ffmpeg -framerate 24 -i frames/frame_%05d.png -b:v 4096k video.mp4

3) Script camera motion with Camera/Controller2

You can define camera waypoints with Camera/Controller2. Each waypoint i has a start time in Time and three input ports: Position<i> (x,y,z), Pitch<i> and Yaw<i>:

<OBJECTS>
<Lib LibName="fhsim_base"
SimObject="Camera/Controller2"
Name="CAM"
NumInput="3"
Time="0,5,10"
UseDegrees="1"
Interpolate="1"/>
</OBJECTS>
<INTERCONNECTIONS>
<Connection
CAM.Position1="-10,0,0" CAM.Pitch1="0" CAM.Yaw1="0"
CAM.Position2="0,-10,0" CAM.Pitch2="0" CAM.Yaw2="90"
CAM.Position3="10,0,0" CAM.Pitch3="0" CAM.Yaw3="180"/>
</INTERCONNECTIONS>
Note
Keep NumInput and the number of Time entries equal to the number of waypoints. Camera/Controller is a second camera object that follows targets with distance, azimuth and elevation.