Good Quality DOSBox Video Capture

By Susam Pal on 01 Sep 2020

Vintage DOS Programs

Once in a while, I fire up one of the vintage DOS games or language interpreters in DOSBox for nostalgia's sake. DOSBox is an emulator program that emulates IBM PC compatible computers running DOS. Trying my hands on these antiquated DOS programs now evokes old memories from my childhood days days when I first came across computers as part of our primary school curriculum.

Computers were much simpler in those days. The ones in our school were IBM PC compatible computers with mostly monochrome displays. A couple of them had support for a very limited number of colours provided by CGA or EGA graphics cards. The ability to boot a computer using a 5¼-inch floppy disk containing MS-DOS, load a Logo or BASIC interpreter, or a computer game from another floppy disk, and then write some programs or play a few games without any distraction had its own charm that I find missing from modern day computing.

Often while using old DOS programs with DOSBox in this day and age, I want to take screenshot captures or video captures of the DOSBox sessions and share them with my friends. In this article, I will explain how I create good quality screenshot captures and video captures of DOSBox sessions in formats that I can share with others.

Contents

Software Versions

Since this article involves several pieces of software, some of what is written here may not hold good in future if the behaviour of any of these software tools change in future. The list below contains the versions of all software tools that were used to test the commands provided in this article:

  1. macOS High Sierra 10.13.6
  2. DOSBox 0.74-3
  3. FFmpeg 4.3.1
  4. ImageMagick 7.0.10-28
  5. IBM Personal Computer Logo Version 1.00
  6. Digger (Original PC booter version by Windmill Software)

Note that both Logo and Digger programs in the list above are DOS programs that were released in 1983. They cannot be run directly on modern computers but they can be run with DOSBox since it emulates old IBM PC compatible computers.

IBM PC Logo in DOSBox

IBM Personal Computer Logo developed by Logo Computer Systems Inc. (LCSI) in 1983 was the first piece of software I got introduced to while learning computers as a kid. I came across it at the age of 8 when I was in Class 4 and our school had a 5¼-inch floppy disk with IBM PC Logo on it. As a result, Logo was the first programming language I learnt in my life. About 20 years later, I would realise that the first programming language I learnt is a dialect of Lisp. How wonderful!

A screenshot of IBM Personal Computer Logo with copyright notices of IBM and LCSI, welcome message, and question mark prompt
Welcome screen of IBM Personal Computer Logo

If the Logo interpreter program LOGO.COM exists in the current directory, it can be run with DOSBox using the following command:

dosbox LOGO.COM

One of the things I enjoyed drawing with Logo was a grid of overlapping circles like this:

A grid made with 20 circles along with Logo source code for it
Grid of circles drawn with IBM Personal Computer Logo

Here is the Logo source code for the above output:

REPEAT 20 [REPEAT 180 [FD 1 RT 2] RT 18]

Digger in DOSBox

At around the same time I learnt Logo, I also came across Digger, a computer game for IBM PC developed by Windmill Software in 1983.

A screenshot of Digger welcome screen with the names and pictures of various game characters with a copyright notice of Windmill Software
Welcome screen of Digger

If the Digger program DIGGER.COM exists in the directory, it can be run using DOSBox with the following command:

dosbox DIGGER.COM -c "config -set cpu cycles=500" -machine cga

The -machine cga option emulates a machine with Color Graphics Adapter (CGA) because Digger requires a machine of this type to run correctly. The cycles=500 configuration option slows down the speed at which DOSBox emulates instructions in order to emulate the slow machines of olden days. Without this option, Digger runs too fast to be able to be conveniently playable.

A screenshot of underground maze in the game of Digger
A game of Digger that has just begun

Digger has an excellent gameplay where the player digs through underground tunnels to pick up emeralds, drop gold bags to release the gold or squash nobbins and hobbins, collect the released gold to earn more points, and so on. It uses bright and attractive colours. The music is great. When Digger was released in 1983, it was quite advanced for its time.

DOSBox Screenshot Capture

The screenshots above were obtained by running IBM PC Logo and the original 1983 PC booter version of Digger on DOSBox and then resizing the screenshots such that their aspect ratio matches the aspect ratio of old CRT computer monitors.

To obtain the screenshots, we first press ctrl+f5 while DOSBox is running. The paths of the screenshots appear in the console output at the terminal where DOSBox was launched. For example:

Capturing Screenshot to /Users/susam/Library/Preferences/capture/logo_000.png
Capturing Screenshot to /Users/susam/Library/Preferences/capture/logo_001.png
Capturing Screenshot to /Users/susam/Library/Preferences/capture/digger_000.png
Capturing Screenshot to /Users/susam/Library/Preferences/capture/digger_001.png

The screenshots obtained in this manner have an aspect ratio of 8:5 which makes the output look stretched horizontally. The old CRT computer monitors for which these old DOS programs were written had an aspect ratio of 4:3 instead. This stretched look can be fixed by resizing the images to an aspect ratio of 4:3. Here are the commands used to fix the aspect ratio and produce the images:

convert logo_000.png -sample '1920x1440!' dosbox-logo-0.png
convert logo_001.png -sample '1920x1440!' dosbox-logo-1.png
convert digger_000.png -sample '1920x1440!' dosbox-digger-0.png
convert digger_001.png -sample '1920x1440!' dosbox-digger-1.png

The convert program comes with ImageMagick. There are a few things worth noting here:

DOSBox Video Capture

To start capturing video of DOSBox, we press ctrl+alt+f5. The same key combination stops capturing video. The following output appears in the console output to show where the video file is saved:

Capturing Video to /Users/susam/Library/Preferences/capture/logo_000.avi
Stopped capturing video.

Say, I want to share a video capture of DOSBox with Logo running on it with my friends who might be on devices that do not support playing AVI files. The following FFmpeg command converts the video to a format that can be distributed widely and played on a wide range of devices and players:

ffmpeg -i logo_000.avi -an -c:v libx264 -preset veryslow \
       -crf 17 -vf format=yuv420p,scale=1920:1440:flags=neighbor,fps=30 \
       dosbox-logo.mp4

Here is what the output looks like:

Video capture of IBM Personal Computer Logo [MP4]

Let us briefly discuss the various FFmpeg options used here:

DOSBox Audio/Video Capture

The video capture of Digger game is processed similarly, however, there are a few additional things we need to take care of. We want to include the game audio in the output file. We also want a higher frame rate because games may sometimes have high-speed motion.

Like before, we use ctrl+alt+f5 to start capturing the video. The same key combination stops capturing video. The following output appears in the console output to show where the video file is saved:

Capturing Video to /Users/susam/Library/Preferences/capture/digger_000.avi
Stopped capturing video.

Here is the command to convert the video capture of Digger to a distributable format:

ffmpeg -i digger_000.avi -c:a aac -b:a 256k -c:v libx264 -preset veryslow \
       -crf 17 -vf format=yuv420p,scale=1920:1440:flags=neighbor,fps=50 \
       dosbox-digger.mp4

Here is the output:

Video capture of Digger [MP4]

Most of the FFmpeg options used in the command above have been discussed in the previous section. Let us discuss the new options used here that have not been discussed earlier:

If we look at the output video above closely enough, we see that the colours don't look as crisp as they do in the Digger game screenshot. The neighbor flag was very effective at maintaining the crisp and jagged edges in the Logo video capture but it does not produce perfect results for the Digger video capture in this section. Despite the imperfection, it is still necessary to specify the neighbor option because without this option, the output video looks even worse. We can use a different pixel format like yuv444p instead of yuv420p to work around this issue. Using the yuv444p format indeed results in perfect nearest-neighbour interpolation which helps in retaining the crisp and jagged edges in the video accurately but as explained in the previous section, many media players currently cannot play this pixel format, so we stick to using the yuv420p format in this article.

DOSBox GIF Animation

Now just for fun, let us see if we can convert the video captures into GIF animations. This can be done quite easily with FFmpeg. Here are the commands to convert the Logo video capture to GIF animation:

ffmpeg -i logo_000.avi -vf palettegen palette.png
ffmpeg -i logo_000.avi -i palette.png \
       -lavfi 'scale=1920:1440:flags=neighbor,paletteuse,fps=30' \
       dosbox-logo.gif

The first command generates a colour palette from the video capture. The second command uses this colour palette to generate a GIF animation. Like before, we use the neighbor flag to retain the crisp and jagged edges. Here is the output:

An animated image of programming in Logo
GIF animation of IBM Personal Computer Logo

Here are the commands to convert the Digger video capture to GIF animation:

ffmpeg -i digger_000.avi -vf palettegen palette.png
ffmpeg -i digger_000.avi -i palette.png \
       -lavfi 'scale=1920:1440:flags=neighbor,paletteuse,fps=50' \
       dosbox-digger.gif
An animated image of a game of Digger
GIF animation of a game of Digger

References

Here is a bunch of references that contains more details about the commands used in this article:

Comments | #dos | #technology