How to make PMODE 4 CSM video files for the CoCo (TRS-80 Color Computer)

Hi All,

Using some awesome free tools a bash script and a little C program I wrote it’s possible to make PMODE 4 colour videos that playback at 23.3 fps with sound and have four colours – black, white,  and the two artifact colours blue and red/orange.  Below I’m going to explain how this all works and how you can make your own.  As an example of what you can expect from this video conversion I’ve uploaded two youtube videos showing the player on a CoCo 1.  The videos can be found here and here, don’t mind the mess on the floor, I usually have my CoCo 3 hooked up but wanted to show this on an actual CoCo model 1 with a 6309 CPU and 64k of RAM.

First we use a fairly recent version of FFMPEG, which is the most amazing video and audio conversion tool there is.  It will take just about any video or audio file as input and convert with filters and effects to many other formats.

First I use FFMPEG to set the frames per second to 23.3 which the CSM player requires.  It also scales the input video width and height so that the aspect ratio is perfect for the CoCo PMODE 4 screen. The format that FFMPEG outputs is 256×192 and will automatically generate black bars on the screen if needed.  It outputs the scaled video as individual still frames/images and numbers them as it produces them.  The images are stored in a folder called pics and are compress LZW – TIFF images.

Next the script uses a picture processing tool called ImageMagick.  ImageMagick is used to do the following things:

  1. Turns yellow pixels to white (ivory)
  2. Resizes the pictures to 128×192 (necessary for making artifacts)
  3. Handles picture levels (black, white and gamma controls)
  4. Normalizes the pictures as the pictures need to be fairly bright or they are hard to make out on the CoCo screen
  5. Remaps the colours of the original image to the black, white (blue, red/orange) colours.  It does this by looking at the palette of a 4 colour GIF file that represents the colours the CoCo 1 can display on a PMODE 4 screen
  6. Dithers that image to make it look like there are more colours on the screen
  7. Flips the image vertically and saves it as an uncompressed 16 colour bitmap (BMP) file.  The BMP format saves every picture upside down, so I flip it before saving it so the data in the file is ready to be used as it is.

Next we use FFMPEG again to process the audio of the source video.  At this point we use FFMPEG to convert the audio of the movie file to 1 channel, 11932 samples/second, unsigned 8 bit audio file.  FFMPEG could have been used to re-encode the video to stills and the audio at the same time but I like to do it separate so that it’s easier on the hard drive other wise you will be reading from the source video and writing both the audio and generating the stills at the same time.

At this point we use FFMPEG to take the sill images and the 8 bit unsigned audio and convert it to a test.mp4 file that can be viewed on your regular computer.  This is a very good representation of how the video will look on the CoCo.  Watching the test.mp4 you can tell if you need to make the output video brighter or not.  This can be done using the -b option with the conversion script.

Next my little C program is executed which takes the BMP stills and goes through each pixel and converts it to either a black set of bits (00) or if it’s orange (01) or blue (10) or white (11) together four times so it has a byte of data and stores that on the buffer.  It does that for the entire picture and then muxes the audio and new video data together in the format the Ed Sniders player will accept.

The last step is to join the CSM header file with the CSM PMODE 4 player code and the muxed audio/video file into one new .CSM file that is ready to be copied to an SD card and played back on the CoCo.

How do I make my own CSM videos?

You must install FFMPEG and ImageMagick on your computer.  If you are on a Mac the easiest way to install the command line tools is using homebrew found here.  Once homebrew is installed on your Mac type brew install ffmpeg and brew install imagemagick to install.  The BASH script and C program I wrote are ready to be used if you have a Mac.

It should work without issues on a Linux box and Cygwin/Mingw on a Windows box.  You will have to compile the program yourself and make sure to install FFMPEG and ImageMagick using your package manager.

Ron Klein is working on ready to go versions for Linux, RPI3 & Windows.  They will be available soon from the link below.

Ed Snider is hosting the files with his other CoCo SDC Media player software.  The Mac version is already available to use and can be found here:

In a folder called Tools for making CSM files.

uncompress the .ZIP file and using the command line in the makecsm folder type:

./ -h

This will give you a summary of the options available for the conversion.  Below is the help you will see:

makecsm – CoCoSDC CSM Video Maker v 1.00
Usage: [-s hh:mm:ss] [-e hh:mm:ss] [-d seconds] [-n] [-h] [-t] [-b 0.00 to 10.00] inputfile [outputfile[.CSM]]

option: -s hh:mm:ss is the time in the video to start conversion
-e hh:mm:ss is the time in the video to end conversion
-d duration in seconds
-n means no artifact colour, make a black and white video
-b x.xx sets the brightness level of the video (1.00 is default)
-h Prints this help message
-t normally a test.mp4 file is created so you can see
the resulting movie on this computer before copying it to the CoCoSDC
this option will disable the creation of a test.mp4 movie

Example: To make a movie from the source movie called mymovie.mkv
Starting at 53 seconds into the video and ending at 1 minute and 30 seconds.
The duration of the video will be 37 seconds. Brighten the video a little
and use the output filename COCOVID.CSM
Command would be: -s 00:00:53 -e 00:01:30 -b 1.1 mymovie.mkv COCOVID.CSM

If no start time or end time is given then the entire video will be converted
If only the start time is given then the conversion will start at the given time
and it will convert the video until the end of the video.
If only the end time is given then the conversion will start from the beginning
of the video up to the end time given.
If no output filename is given then an output file will be created in the
current folder with the extension .CSM

The output filename must be uppercase and be a maximum of 8 characters long,
with the extension .CSM or the CoCoSDC player will not recognize it.

A few little notes on the options, you can select -d 100 (or any number of seconds for the duration) without the -s hh:mm:ss option and it will create a video from the start of the video for the number of seconds in this option (example here of 100 seconds).

You can make a black and white video without artifacts using the -n option.

One last thing to note

If your input or output video filenames have spaces then the script will probably fail.  It will be less troublesome if you move the source videos into the makecsm folder.

How to improve the video quality

The script is pretty straight forward.  Other then FFMPEG creating the images at the correct size all of the image processing is done with ImageMagicks convert command.  If you look up help on ImageMagick there are tons of options.  Maybe going through these options you can find better settings to improve the output quality of the artifact colours.  It’s really hard to get yellows and greens on the CoCo screen so these should probably converted to grey or white.  The current script converts yellow to ivory which is better then converting it to red.  Feel free to tweak the command and if you come up with a really good setting please post it below in the comments.

Last little artifact problem to deal with

When the CoCo 1 or 2 is turned on there is no way to know if the even bits of a PMODE 4 screen make a blue colour or if it’s the odd bits that make the blue colour.  So I wrote a little basic program that I placed on Ed Snider’s PLAY.DSK image.  I called the program GO.BAS and when it is run it fills the screen with the red/orange artifact colour.  The program then asks if the picture is blue, if so then hit reset and start the program again.  If the screen is orange/red then you press a key and it starts Ed’s CSM player.  A copy of this program called GO.BAS is included with the script.  It will need to be copied to Ed’s PLAY.DSK image with imgtool or toolshed or similar utility.

10 CLS
30 FOR X=1 TO 255 STEP 2
40 LINE(X,0)-(X,191),PSET
80 I$=INKEY$
90 I$=INKEY$:IF I$=”” THEN 90

Have Fun,


This entry was posted in CoCo Programming, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s