Add Rimworld post

This commit is contained in:
Florine W. Dekker 2021-07-18 11:08:43 +02:00
parent 09f4e4bff0
commit 8e8f60ae08
Signed by: FWDekker
GPG Key ID: 78B3EAF58145AF25
2 changed files with 136 additions and 1 deletions

View File

@ -24,7 +24,7 @@ This section describes the instructions to be performed before trying to connect
You will only have to follow these instructions once.
0. Make sure SSH is enabled on your Raspi.
If it isn't, follow [⎋ this guide](https://www.raspberrypi.org/documentation/remote-access/ssh/).
If it isn't, follow [⎋ this guide](https://www.raspberrypi.org/documentation/remote-access/ssh/).
1. Install the necessary packages.
$ sudo apt update && sudo apt upgrade

View File

@ -0,0 +1,135 @@
---
title: Creating a Rimworld timelapse
layout: post
date: 2021-07-18
permalink: creating-a-rimworld-timelapse/
excerpt: How to create a timelapse of your Rimworld colony using FFmpeg.
---
You may have seen some beautiful timelapses of [⎋ Rimworld](https://rimworldgame.com/) colonies, including
[⎋one](https://www.reddit.com/r/RimWorld/comments/igy7am/the_noemca_people_tribal_to_space_timelapse/)
[⎋of](https://www.reddit.com/r/RimWorld/comments/jxoo49/timelapse_of_my_frostland_colony_before_it_got/)
[⎋these](https://www.reddit.com/r/RimWorld/comments/ewjruc/timelapse_of_final_base_until_ship_launch_what_a/).
I recently did a timelapse of my 20-year-old medieval colony, and want to share how I created the video.
## 1 Creating screenshots
This is the easy part.
Just install the [⎋ Progress Renderer](https://steamcommunity.com/sharedfiles/filedetails/?id=2010777010) mod
in Rimworld and play your game.
By default, a screenshot will be taken every day at 08:00.
I recommend going to the settings and disabling _designations_, _thing icons_, _game conditions_, and _weather_ in the
settings.
Especially the latter two can cause some jarring effects when you create a video, causing big visual jumps in between
consecutive frames.
This distracts from what you actually want to show:
the changes in your colony!
## 2 Combining screenshots
After you've played the game for a while and had the screenshots created for you, you can combine them into a video.
I used [⎋ FFmpeg](https://ffmpeg.org/) for this, which is a
[⎋ well-known](https://en.wikipedia.org/wiki/FFmpeg) command-line tool for processing video and audio.
It's an extremely powerful tool if you know how to use it, but it's certainly more difficult than other, visual tools.
I think it's a much better alternative than importing all your screenshots into Adobe Premiere though, primarily because
FFmpeg is made to do one thing, and it does it well.
I've seen some people who wrote that they used
[⎋ RimworldRender](https://github.com/Epicguru/RimworldRender).
I don't have any experience with RimworldRender, but I suppose the advantage of FFmpeg is that you can easily combine it
in a whole pipeline of tools and libraries to add music, scaling, zooming, panning, and much more.
You can download [⎋ FFmpeg for Windows from gyan.dev](https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z),
or you can check the [⎋ FFmpeg download page](https://ffmpeg.org/download.html) for more download options.
Simply extract the downloaded archive anywhere you want;
let's say you extracted it to `C:\Users\FWDekker\Downloads\ffmpeg\` so you have the executable
`C:\Users\FWDekker\Downloads\ffmpeg\ffmpeg.exe`.
### 2.1 Renaming the files
Before you can use FFmpeg to create a video from your screenshots, you have to (temporarily) rename the images.
FFmpeg expects the images to have names like `001.png`, `002.png`, etc.
You can easily do that using [⎋ Ant Renamer](http://www.antp.be/software/renamer).
Let's say that your screenshots from Progress Renderer are stored in `C:\Users\FWDekker\Rimworld\`.
1. [⎋ Download](http://www.antp.be/software/renamer/download) and run Ant Renamer.
2. Click the `Add folders...` button, and select the screenshot folder.
3. Press `Actions` in the top left.
4. Go to `Enumeration`.
5. Change the settings to the following values:
* `Mask` to `%num%%ext%`.
* `Start at` to `1`.
* `Number of digits` to `3`.
* `Increment by` to `1`.
These settings are fine even if you have more than 1000 screenshots.
6. Press `Go` at the top.
The files have been renamed, but do not close Ant Renamer yet!
Now you're ready to run FFmpeg.
After you're done with FFmpeg, you can press the arrow to the right of `Go` to undo the renaming.
If you close Ant Renamer, you will not be able to undo the renaming.
### 2.2 Creating the video
With the files properly renamed, you can run FFmpeg to create the video for you.
1. Open the Windows command prompt.
2. Navigate to the directory of screenshots using `cd /d "C:\Users\FWDekker\Rimworld"`.
3. Run the following command:
```shell
"C:\Users\FWDekker\Downloads\ffmpeg\ffmpeg.exe" -f image2 -r 24 -i %3d.png -vcodec libx265 -crf 24 -pix_fmt yuv420p -vf "crop=5120:3680:2384:3296, scale=1280:920, tpad=stop_mode=clone:stop_duration=3" out.mp4
```
* `-f image2` indicates you're going to work with images.
* `-r 24` sets the frame rate to 24 screenshots per second.
* `-i %3d.png` tells what the files are named: three digits following by `.png`.
* `-vcodec libx265` means that you are using the x265 codec.
You can also use `libx264` which is less CPU-intensive, but creates much larger files.
* `-crf 24` is the quality of the video. A lower value means higher quality. Typical values are between 23 and 30.
* `-pix_fmt yuv420p` is the way pixels are encoded.
* `-vf [...]` applies filters to the images, like cropping and scaling.
* `crop=5120:3680:2384:3296` extracts a rectangle from the images, basically zooming in on your images.
The format is `width:height:x:y`, creating a rectangle of size `width` by `height`, with the top-left corner at
`x, y` measured from the top-left corner.
For some reason, you have to make sure all values are multiples of 8, or else you will get a bunch of warnings.
* `scale=1280:920` resizes the video to the given dimensions.
* `tpad=stop_mode=clone:stop_duration=3` freezes the last frame for 3 seconds, to allow people to enjoy the end of
the video.
* `out.mp4` is the file to store the output in.
FFmpeg will show you a nice process indicator with some additional stats, and should be done within a few minutes.
### 2.3 Lowering the quality
If you find that the image is too large, you can repeat the previous step with a higher value for `-crf` or with a
different output size.
However, this means that FFmpeg will have to process all your screenshots again, which takes a while.
Instead, you can just ask FFmpeg to process your existing video to lower the quality as follows, which takes only a few
seconds.
* To change the quality:
```shell
"C:\Users\FWDekker\Downloads\ffmpeg\ffmpeg.exe" -i out.mp4 -crf 28 out2.mp4
```
* To change the size:
```shell
"C:\Users\FWDekker\Downloads\ffmpeg\ffmpeg.exe" -i out.mp4 -vf "scale=640:460" out2.mp4
```
### 2.4 Adding sound
To spice up your video, you can add music.
Store the music file, say `audio.mp3`, in the same folder as `out.mp4`, and then you can use FFmpeg for this step as
well:
```shell
"C:\Users\FWDekker\Downloads\ffmpeg\ffmpeg.exe" -i out.mp4 -i audio.mp3 -af "afade=t=out:st=50:d=3" -c:v copy -shortest out-with-audio.mp4
```
* `-i out.mp4` and `-i audio.mp3` show which files you want to process.
* `-af [...]` applies filters to the audio.
* `t=out:st=50:d=3` means that you're applying the _fade out_ filter, with start time at 50 seconds (`st=50`), and a
duration of 3 seconds (`d=3`).
I chose these values because my video `out.mp4` is 53 seconds long, of which the last 3 seconds are a frozen frame.
If you don't want a fade out, then replace the `-af [...]` with `-a:v copy`.
* `-c:v copy` means that you just want to copy the video without any adjustments.
* `-shortest` takes the shortest of all your input files, and makes the output as long as that file.
So if `audio.mp3` is longer than `out.mp4`, then `audio.mp3` is cut off.
If you used the fade out, you won't hear the cutoff.
* `out-with-audio.mp4` is the file to store the output in.
## 3 Advanced techniques
FFmpeg is a very powerful tool, and if you want to, you can use any of its features to enhance your video.
You can add panning, zooming, and rotating effects with complex filters.
I don't have the experience to tell you how that works exactly, but if you search for `ffmpeg panning` I'm sure you'll
find something useful.