Tips for recording DOSBox video on Linux (on a low-end computer)

This is where you can post your Commander Keen related stories, artwork, or other stuff that is related to Commander Keen but otherwise doesn't belong in another forum.
Post Reply
User avatar
proYorp
Vortininja
Posts: 252
Joined: Fri Mar 03, 2017 1:56
Location: Orbit

Tips for recording DOSBox video on Linux (on a low-end computer)

Post by proYorp »

Estimated reading time: 10-15 minutes


Recently, I finally broke off a longtime relationship with Windows. Never again. I've moved over to Linux, and while I have some experience using it as a live boot for one task or another, using it for my primary operating system is quite a learning curve.

Now, I want to be able to record gameplay of Commander Keen mods, but here's the problem: my laptop is a potato. The thing is 10 years old and wasn't exactly top-of-the-line even when it was new. I'd been able to use DOSBox's built-in recorder with no problems under Windows (the default OS), but there's been a few unique issues that have popped up under Linux and with my specific setup.

It was an entire ordeal, but where there's a will there's a way, and I've managed to get things set up so that I can record DOSBox's video and audio about as smoothly as I can hope. In order to hopefully prevent anyone else from dealing with as many headaches as I had to, I'm writing this guide on what I learned.

It should be noted that all the Linux distributions I have experimented with are Debian-based. Given the variety between different Linux distros, I can't guarantee that these tips will work on any others.





Section I -- DOSBOX built-in video recorder


One of my favorite features of DOSBox, and the first screen recorder I had access to. Even for personal use, it's a lot better than screenshots for capturing cool moments! An interesting effect of using the built-in recorder is that any lag caused by the recording process will not be captured in the video file, only showing what was rendered inside of DOSBox's simulation and not how it displayed on your screen. This also applies to other effects external to the actual game emulation, such as DOSBox's fast-forward function. As such, if you're going to be recording a calm area with no hazards in the game, you could get away with using the built-in recorder even if it lags because it won't show up in the video. However, if you're going to be needing any kind of reaction time to play, you'll want to get rid of as much lag as possible.

Now, onto the tips.



DON'T USE CTRL - ALT - F5. This applies no matter how much horsepower your computer has. This is the default key combo that DOSBox uses to start its video capture, which works fine under Windows, but Linux uses this combination to initiate something called tty5, which turns your whole screen into a big scary-looking terminal. If you find yourself in this position and want to escape back to the comfort of a graphical environment, press Ctrl + Alt + F7.

It is possible to disable the tty5 so that Ctrl + Alt + F5 does nothing by itself, but it is a lot simpler (and much less risk of messing up something important) to reconfigure DOSBox to use a different shortcut to record video.

For the beginners:
To assign a different shortcut to DOSBox's video recording, open DOSBox and press Ctrl + F1 (or Ctrl + Fn + F1 if your keyboard requires it) to open the keymapper. Click the box that says "Video", click "Add", press the key you would like to use to toggle video capture, and if you want the shortcut to also require the simultaneous use of Ctrl and Alt (probably a good idea if you don't want to accidentally record video every time you hit your designated key), check the boxes at the bottom of the screen that say "mod1" and "mod2" (these default to "left ctrl" and "left alt", respectively). Click "Save".



VLC DOES NOT DOSBOX. VLC is a video player that comes built-in with many Linux distros, but it doesn't seem to get along well with the ZMBV video codec that DOSBox uses.

One example: It can't seem to handle palette changes that occur during the video. After trying to use DOSBox's recording function on a changed-palette mod, I looked at the footage in VLC and was dismayed to find that the colors displayed were default EGA (all the wrong colors). After some puzzled experimentation, I went and grabbed MPV (another video player) and opened that file, and behold, the colors displayed as they appeared in DOSBox. It wasn't a problem with the video, just VLC.

Another example of VLC's limitations: While trying to figure out just what was wrong with my recording, I tried to open some older DOSBox-created videos that had been recorded under Windows. VLC played the sound from the recording, but only displayed a black screen. I knew these files were fully functional, which is what led me to try a different video player.

Interesting trivia discovered here:
Another effect of the lack of palette shifting is that the fade in/out effect, seen when entering a level for instance, doesn't show up. Instead it displays a hard cut between the fully illuminated world map and new level. This makes it possible to see that in Vorticons Keen, sprites aren't rendered until a frame after the tiles.

The standard patch that is used for palette modification seems to apply the new colors shortly after the game has already initiated. When I started the recording while in the DOSBox console before running the batch file to play the mod, the colors displayed as EGA in the video output, as stated above. However, if the recording was started after the mod was already in the main menu, VLC had no problems seeing the new colors. I tried this with a few changed-palette mods and the effect was the same. The only exception was Operation Ocflore, which instead defines the colors with a command before the game opens. As a result, the palette doesn't change after the mod initiates, and so DOSBox's recording of the program doesn't confuse VLC.



WRITE SPEED IS IMPORTANT. Here's where we start getting into computer performance. When I started testing DOSBox recording on this OS, I was running unmodified Keen 1 and noticed some pretty constant frame lag while recording was active. This didn't make any sense at first, because I had recorded Vorticons gameplay under Windows before and had no performance issues, and everything I knew about Linux indicated that it should, in general, be more efficient on resources than Windows.

It came to me that the issue might just be the fact that I'm currently booting off of a USB thumb drive. (Not exactly an ideal setup, but for right now it's all I got!) USB, especially the older USB 2.0, has a much slower read/write speed than SATA (a standard port used for internal hard drives). As you might assume, Windows had been running off of the internal hard drive, and writing DOSBox video output to it as well. I don't boot from the hard drive anymore, but I still have it inside my laptop. So I thought, "what if I get DOSBox to write the video to the hard drive?"

By default, DOSBox records video to "~/.dosbox/capture" located in your home directory. Since I'm running Linux from a USB thumb drive, my home directory is also stored on the thumb drive. For a quick'n'dirty fix to move the output to the internal hard drive, I went and created a folder somewhere on my hard drive called "capture2". Then I created a symbolic link to that folder inside the "~/.dosbox" directory, and in the DOSBox config file (which is "~/.dosbox/dosbox-0.74-3.conf" for my version) changed the line under the "[dosbox]" section from "captures=capture" to "captures=capture2".

After making this change, I went back and tested again, and vanilla Keen 1 no longer had any frame lag while recording! Who'd've thought. Write speed makes a difference, at least at this level of bare-minimum computing power.

IMPORTANT: Make sure the drive you are recording to is mounted (with read/write access!) before starting to record, otherwise that video output will go nowhere. (And it's not just the video; screenshots and sound are also output to the capture directory!) If you have DOSBox running from a terminal window, it will tell you that it can't open the directory.

More interesting trivia:
While trying to determine the source of the lag, I tested recording a clip of Operation Ocflore, since that was something I had recorded under Windows without many problems. Surprisingly it worked a lot better than vanilla Keen 1, only having lag spikes every 10 seconds or so, whereas Keen 1 had nearly constant frame lag. I guess it must be because despite having a heavier graphical engine, "Goodbye, Galaxy!" had a lot of optimizations added that weren't in "Invasion of the Vorticons" according to this commentary on the production.





Section II -- External screen recorder


But what if it all still isn't enough? If DOSBox still lags while recording, what can be done? Or, maybe you don't want to fill your hard drive with gigabytes of uncompressed video. Seriously, a half hour recording of raw DOSBox video output at the tiny DOS resolution of 320x200 is 373.5 MB, and the same video upscaled to 1280x800 and compressed is 173.0 MB -- less than half the size! As great as it is that DOSBox even has a built-in video recorder, in some cases it may just be a better choice to use something else.

Anyone with a half-decent amount of CPU and RAM will tell you to use OBS Studio, and that was the first thing I tried. However, upon trying to open the program, OBS told me, and I quote, "get a better computer lol" and did not offer me so much as the courtesy of starting up. How rude.

Fortunately, lightweight recording software does exist, thank goodness! I've found one that fits all my needs, and during approximately two hours total of recording there was only about a second of noticeable lag, which is about as good as I could possibly hope for given my meager resources. It's called SimpleScreenRecorder.


SIMPLESCREENRECORDER. There is a fair, but not overwhelming, amount of settings in this program, and after some fiddling I found a good combination to get the fantastic results I mentioned. As I am nearing the end of my desire to continue writing words for this already lengthy essay, rather than giving a detailed analysis on every option in the program, I'll just provide the list of settings I used with some notes.

Code: Select all

VIDEO INPUT
 - Select option "Record a fixed rectangle"
Left: [current x position of window]
Top: [current y position of window]
Width: 640
Height: 400
Frame rate: 30
 - Check option "Scale video"
Scaled width: 320
Scaled height: 200
 - Uncheck option "Record cursor"


VIDEO OUTPUT
FILE
Save as: [base filename and directory]
 - Uncheck option "Separate file per segment"
 - Check option "Add timestamp"
Container: Matroska (MKV)

VIDEO
Codec: H.264
Constant Rate Factor: 23
Preset: superfast
 - Check option "Allow frame skipping"
To use SimpleScreenRecorder, I left DOSBox in windowed mode at the default 2x resolution scale, which displays Commander Keen at 640x400. After positioning the DOSBox window where I wanted it to be while playing, I clicked the "Select window..." button under SimpleScreenRecorder's video input section, then clicked the middle of DOSBox's window to set the recording area. I enabled the "Scale video" option to downscale the video back down to 320x200, because this seemed to be easier on performance in this case. Also uncheck "Record cursor" please. It is not used at all when playing Keen and it is annoying when a video has a cursor stuck in the corner the whole time.

From my experiments, SimpleScreenRecorder looks to store the video in memory until it is stopped rather than writing it progressively to the hard drive as DOSBox does. Because of this, there may not be any performance benefits during recording from configuring SimpleScreenRecorder to write to the hard drive instead of the thumb drive. However, it may still be preferable as hard drives tend to contain quite a bit more storage space than thumb drives. If you do -- again, remember to mount the hard drive before recording!

IMPORTANT: Remember to select your recording area at the start of every session. There's a good chance the DOSBox window will be in a different place every time! Tip: after clicking the "Select window..." button, to record only the game display of DOSBox, click the middle of the window, but to include the window border and top bar, click anywhere on the window border. If you hold down the mouse button when selecting the recording area it will display a box around the area it is selecting.



I implied at the start of this section that using an external screen recorder should help with frame lag while recording. My theory for this was that since DOSBox is both drawing an image on the screen and outputting it to a file while using its recording function, it might slow down its rendering speed. (Especially since, as noted earlier, when using DOSBox's built-in recorder, the video contains exactly what was simulated inside DOSBox, no more and no less. This could possibly indicate that it might try to wait until the frame is saved before trying to draw another one, which could theoretically cause delays.) Coming to this conclusion is what led me to try the external recorder idea, and it sure seems like it worked!

Being an external program it shouldn't cause any direct interruptions to DOSBox's rendering, and the only concern would be if it uses too much CPU on its own. However, here that wasn't a problem, which is probably largely due to working with such small resolutions. An external video recorder could even theoretically be separated to run on a different CPU thread entirely. (Despite my CPU being slower than most smartphones nowadays, it does at least have two cores!)





Conclusion


I suppose this guide is for a highly specific situation. I find it interesting how Commander Keen is probably one of the most accessible games as far as compatibility and expense goes (including the part where low-end hardware is a lot cheaper), whereas video capture is one of the most resource-intensive activities. Probably any computer made within the last 3 decades can run Commander Keen (although I wonder if there is gap of computers too new to run DOS and too old to run DOSBox). So if you're like me and are stuck with older hardware for whatever reason and are absolutely dead set on getting gameplay video capture to work then hopefully you will get some use out of this. Or if you just want to read about the weird trivia I found while doing this. Hopefully it's interesting. If anyone ever finds this helpful, please let me know!





Coming up next time: How to play Keen mods with a broken left arrow key
"Friendly. Very friendly. Too friendly." Image
User avatar
Nisaba
Vorticon Elite
Posts: 1343
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by Nisaba »

thanks for your in depth field report. some of your reported challenges reminded me a lot of my first steps on Unix based systems. 10 years ago I would have wished to find a "tutorial" like yours to shortcut at least some of the hassle I had. I think it's a great that you share your knowledge about this very specific topic. and I'd like to invite you to supplement our wiki Linux topic over here: https://keenwiki.shikadi.net/wiki/Keen_ ... ing_DOSBox

Coming up next time: How to play Keen mods with a broken left arrow key
haha! I also once had a machine with broken keys. fortunately DOSBox' build-in keymapper allows to change the default keybindings to tackle this issue
Foray in the Forest progress:
92% Programming || 95% GFX || 92% Levels || 98% Creatures || 90% Story || 94% Music || 95% SFX || 96% Extras

Other projects:
- Play Commander Keen on a GameBoy
- The Lynx Nyx
User avatar
proYorp
Vortininja
Posts: 252
Joined: Fri Mar 03, 2017 1:56
Location: Orbit

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by proYorp »

Ha yeah, that's what I ended up doing. I'd tried to use something called xmodmap to temporarily remap the keys on a system level but for some reason that isn't picked up by DOSBox so I gave up on that one. Using IJKL as arrow keys is surprisingly intuitive; doesn't confuse my muscle memory at all. Fun fact: I can still type the "exit" command in DOSBox while the letter keys are also used as arrows, as long as it's the first command typed into the console. Otherwise when I hit "i" it just goes up to the last command used.

Thanks for the invitation. I've been meaning to get a KeenWiki account since forever but the registration process is a bit intimidating. (I need to give my name? And what would a resume even be used for here??)

By the way, did you still have any plans to write that tutorial on how to make DOSBox clips into gifs? ;)
"Friendly. Very friendly. Too friendly." Image
User avatar
Nisaba
Vorticon Elite
Posts: 1343
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by Nisaba »

keenwiki account
a resume is to tell you apart from bots, trolls and people who try to spam the place with adverts. you can basically look at it as sort of a safety precaution. If you write something Keen related I'll be happy to activate your keenwiki account.


turn DOSBox video clips into gifs
I thought I already wrote a little "how to". Well, here's the way I proceed on a Debian (Linux) based system.
First of make sure you've installed ffmpeg, imagemagick and a couple of codex'.

Code: Select all

sudo apt install ffmpeg imagemagick libavcodec-extra
Next record a video with DOSBox’ the build in video capturing feature. You can find the recorded AVI video in this folder

Code: Select all

~/.dosbox/capture/
Open up a terminal and make sure to change the directory towards where DOSBox stores captured material:

Code: Select all

cd ~/.dosbox/capture
Now it's time to extract all frames of the video by running the following command. Beforehand either change the parameter "in.avi" or rename the video file itself that you want to convert, so that both names match.

Code: Select all

ffmpeg -i in.avi -sws_flags neighbor+full_chroma_inp -s 320x200 -f image2 %03d.png
Depending on the duration of your video quite some image files should get extracted. Now scan those files and check at which number your animation should start and where the loop should set in. Note down both file numbers.
When done run the following command to convert those image files into one looping gif file. The parameter "001 2 999`" tells the program the range of files to include. If you want to change the starting point to let's say image #34 and define #123 as the last image then you want to change this parameter like so: "034 2 123`"

Code: Select all

convert -delay 1x30 `seq -f %03g.png 001 2 999` -fuzz 1% -ordered-dither o8x8,4 -coalesce -layers OptimizeTransparency +map animation.gif
Depending on the number of images that the program needs to edit and of course depending on the power your system provides, this process might take a while. When done you should find a new file called "animation.gif" within this folder.
Foray in the Forest progress:
92% Programming || 95% GFX || 92% Levels || 98% Creatures || 90% Story || 94% Music || 95% SFX || 96% Extras

Other projects:
- Play Commander Keen on a GameBoy
- The Lynx Nyx
User avatar
K1n9_Duk3
Vorticon Elite
Posts: 749
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by K1n9_Duk3 »

Nisaba wrote: Tue Jun 22, 2021 9:06 I also once had a machine with broken keys. fortunately DOSBox' build-in keymapper allows to change the default keybindings to tackle this issue
proYorp wrote: Wed Jun 23, 2021 5:56 Ha yeah, that's what I ended up doing. I'd tried to use something called xmodmap to temporarily remap the keys on a system level but for some reason that isn't picked up by DOSBox so I gave up on that one
Er... you know that all of the Keen games allow you to customize your controls, right?

In Keen 1-3, pressing F3 brings up the keyboard configuration window.

In Keen 4-6, select "Configure" -> "Use Keyboard" -> "Movement" (you can use the mouse to move up and down in the menus).

You can do that instead of messing with the keymapper. This way the remapped controls won't prevent you from typing any text. Just memember to "quit to DOS" instead of closing the DOSBox window, otherwise your new settings won't be saved to disk.
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net
User avatar
Nisaba
Vorticon Elite
Posts: 1343
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by Nisaba »

...given that Keen is the only application you are about to run in DOSBox...
Foray in the Forest progress:
92% Programming || 95% GFX || 92% Levels || 98% Creatures || 90% Story || 94% Music || 95% SFX || 96% Extras

Other projects:
- Play Commander Keen on a GameBoy
- The Lynx Nyx
User avatar
proYorp
Vortininja
Posts: 252
Joined: Fri Mar 03, 2017 1:56
Location: Orbit

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by proYorp »

Nisaba wrote: Wed Jun 23, 2021 8:33 keenwiki account
a resume is to tell you apart from bots, trolls and people who try to spam the place with adverts. you can basically look at it as sort of a safety precaution. If you write something Keen related I'll be happy to activate your keenwiki account.
I think you're talking about the personal bio/user page. I understand that part. What I'm talking about is the part that says "Resume or CV," which is a detailed report on an individual's education and work history, which seems quite outside of the scope of KeenWiki. Granted, it's "optional," but why should it be an option in the first place? I should probably be asking Malvineous about this....

turn DOSBox video clips into gifs
I thought I already wrote a little "how to". Well, here's the way I proceed on a Debian (Linux) based system.
Oh, you did? I can't seem to find the thread. Thanks for posting it here! I had my eye out for that ever since you mentioned that you might write a guide on it ages ago. :)



K1n9_Duk3 wrote: Wed Jun 23, 2021 20:32 Er... you know that all of the Keen games allow you to customize your controls, right?
:lol Of course I know about the control configuration menus. I may be a noob to Linux, but I ain't no noob to Keen.

I have to provide a slight correction there. ;) All of the official Keen games allow you to customize the controls. A certain mod I was trying to play has hardcoded arrow keys, which is what sent me down this particular rabbit hole. Oh, the control menu may still be there, it just might not necessarily have an effect. Probably not something anyone would ever even notice unless they've landed in the exact same situation as me.

Besides, using the DOSBox keymapper means I don't have to put a new weird control scheme into every single mod. Work smarter not harder!

As for ability to type text, in Keen 4-6 the letters are placed before it tries to use the keypress as an arrow key, so it overall works alright. "J" is a bit wonky since it pulls the text cursor back (while functioning as left arrow), but my right arrow key is working fine so I can correct it afterwards. In Keen 1-3 the letters don't take, but typing is only really used for high scores and my username does not include I, J, K, or L so it's fine for me. In a pinch the configuration could be reverted temporarily.

...I was joking about writing a tutorial on how to play mods without an arrow key but I guess I'm practically doing that already, heh.
"Friendly. Very friendly. Too friendly." Image
User avatar
Nisaba
Vorticon Elite
Posts: 1343
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by Nisaba »

proYorp wrote: Sun Jun 27, 2021 1:47 What I'm talking about is the part that says "Resume or CV," which is a detailed report on an individual's education and work history, which seems quite outside of the scope of KeenWiki. Granted, it's "optional," but why should it be an option in the first place? I should probably be asking
aha! thanx for the report. As the keenwiki got recently updated this option most likely slipped our attention. This is definitely something we need to remove. So, yeah, might be best if you inform Malvineous about this...
proYorp wrote: Sun Jun 27, 2021 1:47 turn DOSBox video clips into gifs
Oh, you did? I can't seem to find the thread. Thanks for posting it here! I had my eye out for that ever since you mentioned that you might write a guide on it ages ago. :)
yeah, check this viewtopic.php?p=83725#p83725
or that post viewtopic.php?p=81136#p81136
Foray in the Forest progress:
92% Programming || 95% GFX || 92% Levels || 98% Creatures || 90% Story || 94% Music || 95% SFX || 96% Extras

Other projects:
- Play Commander Keen on a GameBoy
- The Lynx Nyx
User avatar
proYorp
Vortininja
Posts: 252
Joined: Fri Mar 03, 2017 1:56
Location: Orbit

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by proYorp »

Ah okay, I did find those posts while I was trying to see if you'd already posted a tutorial. I guess it's the same program, though that guide seems to be more geared towards upscaling videos rather than converting to gif, so I didn't realize that it could do both. I'm a baby Linux user and I need specific step-by-step instructions. :helmet FFmpeg has so many parameters....
"Friendly. Very friendly. Too friendly." Image
User avatar
Nisaba
Vorticon Elite
Posts: 1343
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by Nisaba »

I'm sure there are also applications out there that come with a graphical user interface. This should make things way easier, especially if you are new to Linux.
This is just my preferred routine as it allows me to control each and every parameter. But yeah, working with the command line interface can get quite overwhelming especially if you work with a feature rich program like ffmpeg.

As you are new to the Linux world you might be interested to hear that nearly every program comes shipped with a manual. To open it simply type "man ffmpeg" (or "man firefox" or any other tool) into your terminal. Here you'll find a description, options and parameters and so on. This can be quite helpful to learn more about your applications and how to use them.

anyhow, please let me know if something is still unclear or if you have further questions. We all started our Linux journey somewhere. and at the beginning there are definitely quite some question marks. I'll be happy to help where I can. And if you need a more detailed step-by-step guide, just let me know
Foray in the Forest progress:
92% Programming || 95% GFX || 92% Levels || 98% Creatures || 90% Story || 94% Music || 95% SFX || 96% Extras

Other projects:
- Play Commander Keen on a GameBoy
- The Lynx Nyx
User avatar
Soul Monster
Vortininja
Posts: 75
Joined: Mon Jun 14, 2021 2:47

Re: Tips for recording DOSBox video on Linux (on a low-end computer)

Post by Soul Monster »

Well, that made for an interesting read. Thanks for posting this.

Also, when you've had some time to get acquainted with how to use linux, PLEASE write about your experience using it.
I too have become increasingly disenchanted with Windows and am seriously considering gradually moving over to linux in the next few years,
and would enjoy hearing about how it goes for you, as well as how you get around some of the compatibility issues some of my friends who used it
have told me about.
Post Reply