Good Quality DOSBox Video Capture
IBM/LCSI Logo in DOSBox
Once in a while, I fire up one of the vintage DOS games or language interpreters in DOSBox for nostalgia's sake. I have archived these vintage programs at https://github.com/susam/dosage. Last night, I picked up IBM Personal Computer Logo developed by Logo Computer Systems Inc. (LCSI) in 1983.
Logo was the first programming language I learnt in my life. 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. About 20 years later, I would realize that the first programming language I learnt is a dialect of Lisp. How wonderful!
One of the things I enjoyed drawing with Logo was a grid of overlapping circles like this:
Here is the Logo source code for the above output:
REPEAT 20 [REPEAT 180 [FD 1 RT 2] RT 18]
DOSBox Screenshot Capture
The screenshots above were obtained by running IBM Personal Computer Logo Version 1.00 in DOSBox v0.74-2 in macOS High Sierra version 10.13.6 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
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 '640x480!' dosbox-logo-0.png convert logo_001.png -sample '640x480!' dosbox-logo-1.png
convert program comes with ImageMagick. There are a few
things worth noting here:
We use the
-sampleoption here to resize the image as opposed to using
-scaleoption would smooth the jagged edges in the text and graphics with additional grey shades. The
-resizeoption is great for real world images where we do want the edges to be smooth while scaling up or down but in these screenshots we want to retain the crisp and jagged edges that is typical of DOSBox and the old CRT monitors. Therefore we use the
-sampleoption that does not introduce any new colours. Instead it uses nearest-neighbour interpolation (point sampling) to decide the colours of the scaled image.
!flag is used to ignore the aspect ratio of the original image. Without this flag, the output files would be 640x400 in size, i.e., the largest size with an aspect ratio of 8:5 that fits in a 640x480 box. With this flag, the original aspect ratio of 8:5 is ignored and the output is exactly 640x480 in size.
By the way, I have donated both images above to Wikimedia Commons under the Creative Commons Attribution 4.0 International (CC BY 4.0) license:
Having the images on Wikimedia Commons helps to include these screenshots in the Wikipedia article on Logo.
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.
Now I wanted to share this video with my contacts who might be on devices that do not support playing AVI files, so I decided to convert this to MP4 format with the following FFmpeg command:
ffmpeg -i logo_000.avi -an -c:v libx264 -crf 17 -preset veryslow \ -pix_fmt yuv420p -vf scale=640:480:flags=neighbor \ dosbox-logo-circles.mp4
Here is what the output looks like:
Let us briefly discuss the various FFmpeg options used here:
This, of course, specifies the input file.
We do not have any audio in this video, so we reduce the file size a little by disabling the audio stream with this option. For example, without this option the output file size was 352 KB but with this option it turned out to be 312 KB.
This option should not be specified if the audio stream needs to preserved, for example, with DOS games that have audio.
This option provides visually lossless output, i.e., high quality output without any loss in quality that can be perceived by human eyes. For completely lossless output, we need to use the
-crf 0option. The
-crf 51option produces the most lossy (worst quality) output.
This option provides better compression at the cost of encoding speed. For example, without this option it produces an output of size 328 KB in about 2.2 seconds on my system but with this option it produces an output of size 312 KB in about 6.2 seconds on the same system.
This option ensures that the output video file can be run in a wide range of devices and players.
For example, without this option, we get the output in the YUV444p format. I found that QuickTime Player version 10.4 on macOS High Sierra as well as Android 9.0.0 was unable to play this format.
$ ffmpeg -v quiet -i logo_000.avi -an -c:v libx264 -crf 17 -preset veryslow dosbox-logo-circles.mp4 $ ffprobe -v error -show_entries stream=codec_name,profile,pix_fmt dosbox-logo-circles.mp4 [STREAM] codec_name=h264 profile=High 4:4:4 Predictive pix_fmt=yuv444p [/STREAM]
With this option, we get the output in the YUV240p format. Now both QuickTime Player version 10.4 as well as Android 9.0.0 could play this format.
$ ffmpeg -v quiet -i logo_000.avi -an -c:v libx264 -crf 17 -preset veryslow -pix_fmt yuv420p dosbox-logo-circles.mp4 $ ffprobe -v error -show_entries stream=codec_name,profile,pix_fmt dosbox-logo-circles.mp4 [STREAM] codec_name=h264 profile=High pix_fmt=yuv420p [/STREAM]
For maximum compatibility with old devices, we could add the
-profile:v baseline -level 3.0options too. However, we need to keep in mind that this baseline profile does not support lossless encoding with the
-crf 0option. The least lossy encoding option we can specify with this profile is
-crf 1which while not technically lossless is much better than visually lossless.
$ ffmpeg -v quiet -i logo_000.avi -an -c:v libx264 -crf 17 -preset veryslow -pix_fmt yuv420p -profile:v baseline -level 3.0 dosbox-logo-circles.mp4 $ ffprobe -v error -show_entries stream=codec_name,profile,pix_fmt dosbox-logo-circles.mp4 [STREAM] codec_name=h264 profile=Constrained Baseline pix_fmt=yuv420p [/STREAM]
Finally, we resize the video to maintain an aspect ratio of 4:3, i.e., the aspect ratio of the old CRT computer monitors, so that the output looks similar to how it used to look on those monitors.
neighborflag ensures that the nearest-neighbor interpolation (point sampling) is used to decide the colours of the scaled image. Without this option, the default bicubic interpolation algorithm is used. It has the effect of smoothing the edges with grey shades. While such smoothing of edges is good for scaling pictures of the real world, in this case, it spoils the crisp and jagged edges that is typical of output visible in DOSBox or the old CRT monitors. With the
neighboroption, we retain the crisp and jagged edges visible in the original video capture.
DOSBox GIF Animation
Now just for fun, let us see if we can convert the video capture into a GIF animation. This can be done quite easily with FFmpeg like this:
ffmpeg -i logo_000.avi -vf palettegen palette.png ffmpeg -i logo_000.avi -i palette.png \ -lavfi 'fps=30,scale=640:480:flags=neighbor,paletteuse' \ dosbox-logo-circles.gif
The first command generates a color palette from the video capture. The
second command uses this color palette to generate a GIF animation. Like
before, we use the
neighbor flag to retain the crisp and
jagged edges. Here is the output:
Here is a bunch of references that contains more details about the commands used in this article: