Jump to content

Smoothing out Gameplay Footage


Capital_Asterisk

Recommended Posts

Overview

This guide is for people who make KSP videos that involve a high part count, lots of explosions, decoupling, or rockets igniting.

Requires external software: FFmpeg
This means a bit of command line keyboard smashing is also required.

Problems to deal with:

  • The game almost always runs slow regardless of hardware
  • Long stutters: a few exploding parts can freeze the game for a few seconds or minutes.
  • Inconsistent time difference between rendered frames: time in-game will not match the real world or recorded time.
  • Skipped physics frames: at low frame rates, many physics frames are skipped and won't be rendered.

The normal way of dealing with this is to just speed up gameplay footage fast enough so that all this is unnoticeable. However, things like explosions will still stutter the footage, and the game speed will still vary throughout recordings.

The solution:

  • Edit settings.cfg to make time between each rendered frame consistent
  • Remove duplicate frames from recorded footage.

The consequences of using this method:

  • The game will be limited to 25 fps. This is probably okay as it almost never goes this high anyways.
  • Extra video processing step takes time and video quality might be affected
  • Audio is not preserved

Results:

Correctly processed but slightly boring video:

 

About 30 seconds of in-game time, but >1 hour of irl recording. Audio was manually added in, and the method wasn't finalized here making it run too fast during the collapse.


How to

Step 1: Edit settings.cfg

This file is located in the root of the KSP folder ( Kerbal Space Program/settings.cfg ). It is normally modified by the title screen settings. Editing it manually will allow using values that aren't in the settings.

KSP physics runs at a fixed 50 FPS internally, or in 0.02s steps. If display framerate is greater than 50, then physics frames will be interpolated between frames. If the drawing framerate is lower, then the game will skip frames. The number of frames KSP is allowed to skip is mostly determined by "Max delta time per frame" in the settings, or the maximum allowed physics time between rendered frames. Setting this to a small number will mean that KSP will not skip frames at all; however, this is wrong. Even when it's set to 0.01, KSP will still skip at least one frame when running slow, which means 25 FPS is the max guaranteed-consistent stock frame rate. 

The frame rate has to be limited to 25, which there's an option for. V-sync should also be disabled to make this work.

Find the following values and set them accordingly:

PHYSICS_FRAME_DT_LIMIT = 0.01
SYNC_VBL = 0
FRAMERATE_LIMIT = 25

 

Step 2: Recording and removing duplicate frames

Record at a framerate a little higher than 25 FPS, such as 30 just to assure that no frames are missed. Any common video format should work. Do not record your cursor, as it can move while KSP is frozen, messing up duplicate frame detection.

Install FFmpeg, this is a very powerful command line tool you should always have lying around when dealing with video files. If you're on Linux then you know what to do; if not, then make sure to download an executable, not the source code. For windows, I'd recommend using an ffmpeg-...-win64-gpl-shared.zip from here.

There's a few guides on the first results of google on how to "install" it. I reccomend this guide for Windows.

Now open your favourite command line terminal, every OS should have one installed, such as cmd on Windows.

First off, check if ffmpeg is working by running the ffmpeg command. It should output something like this:

>ffmpeg
ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
.... lots of stuff go here

Set current directory to where your recordings are using the cd command. You can drag files into the terminal window to automatically type their full path.

cd path/to/recordings/folder

Now time to actually remove duplicate frames. We'll be using FFmpeg's mpdecimate filter to drop duplicates, and setpts to set duration of these duplicates and also set the output framerate.

Here's the minimal example of the command used to do this. Replace bold and underlined fields with your own values. Ignore FRAME_RATE and N.

    ffmpeg -i InputFile -an -vf mpdecimate,setpts=N/FRAME_RATE/TB*InputFPS/OutputFPS,fps=OutputFPS OutputFile

InputFile - Path to your recorded game footage
InputFPS - Framerate InputFile was recorded in
OutputFile - Name of output file that will be created
OutputFPS - Output frame rate. use 25 in this case.

-i is for input
-an removes audio
-vf is for video filter

For example, a recording at 48FPS:

ffmpeg -i 'MyRecording.mp4' -an -vf mpdecimate,setpts=N/FRAME_RATE/TB*48/25,fps=25 'MySmoothRecording.mp4'

This might take a while to process.

Preserving quality (for h.264 mp4)

FFmpeg has to re-encode the entire video, and by default, sets quality to a crf 'constant rate factor' of 23. Lower CRF numbers are better, and 23 has noticable compression artifacts.

Add the `-crf 10` or something to avoid getting jpegged.

ffmpeg -i 'MyRecording.mp4' -an -vf mpdecimate,setpts=N/FRAME_RATE/TB*48/25,fps=25 -crf 10 'MySmoothRecordingHD.mp4'

I'll admit that video codecs and stuff is not at the best of my knowledge. This just works.


Some extra notes and details

This method is not the best way to record smooth KSP footage. The best way is probably to write a mod that records the game, or sets constant frame rates.

 

 

Edited by Capital_Asterisk
Link to comment
Share on other sites

  • 4 months later...
On 11/10/2020 at 4:51 PM, Capital_Asterisk said:

About 30 seconds of in-game time, but >1 hour of irl recording. Audio was manually added in, and the method wasn't finalized here making it run too fast during the collapse.

How was the audio synchronized?

(I'm guessing it's tedious)

Edited by Pipcard
Link to comment
Share on other sites

  • 4 weeks later...

[wrong example apparently. carry on]

 

On 11/11/2020 at 1:51 AM, Capital_Asterisk said:

The normal way of dealing with this is to

..use video editing software, which is designed exactly to handle/correct many of these things.

I get that people are loathe to spend money, but seriously, this is what video editors are for. And if you look around, you can get pretty good deals, no need to spend a lot.

https://www.humblebundle.com/software/vegas-pro-discover-your-endless-freedom-software?hmb_source=&hmb_medium=product_tile&hmb_campaign=mosaic_section_1_layout_index_1_layout_type_threes_tile_index_1_c_vegaspro_discoveryourendlessfreedom_softwarebundle

 

Edited by swjr-swis
scratch
Link to comment
Share on other sites

On 5/1/2021 at 1:17 PM, swjr-swis said:

..use video editing software, which is designed exactly to handle/correct many of these things.

I get that people are loathe to spend money, but seriously, this is what video editors are for. And if you look around, you can get pretty good deals, no need to spend a lot.

https://www.humblebundle.com/software/vegas-pro-discover-your-endless-freedom-software?hmb_source=&hmb_medium=product_tile&hmb_campaign=mosaic_section_1_layout_index_1_layout_type_threes_tile_index_1_c_vegaspro_discoveryourendlessfreedom_softwarebundle

 

I'm curious as to how you'd do this with Sony Vegas. I haven't been able to find anything to remove duplicate frames specifically.

Link to comment
Share on other sites

3 hours ago, Stratzenblitz75 said:

I'm curious as to how you'd do this with Sony Vegas. I haven't been able to find anything to remove duplicate frames specifically.

The link I posted was just the first search hit of the kind of deals I mentioned.... not an endorsement of a specific software package. It may not be the best fit.

Doesn't Vegas support plugins/filters - just like After Effects/Premiere, Final Cut, etc?  I realize though that that means it wouldn't be the video editor itself doing it, so my comment is out of place. I'll scratch it.

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...