The.Matrix-ASCII Process

Click to view the pictorial process page.

I used serveral different programs, scripts and platforms to go from The Matrix to The.Matrix-ASCII. The scripts are very simple. The bulk of the time for the conversion was determining what settings I thought were best.

The first step is to get the frames from the DVD.
mplayer dvd://1 -benchmark -noframedrop -nosound -vo jpeg

I tried to use mplayer for extract the ac3 file but it gave me an error during the extraction. I used DVD2AVI instead.

I tried to get aview to output the ASCII to stdout. When I did this I lost some of the information such as bold and reverse characters. I ended up modifying aview to run xwd and then exit. I felt this was a cheap way out but it was quick, easy, and did exactly what I wanted.

diff -Nru aview-1.3.0/main.c aview-1.3.0-jz/main.c
--- aview-1.3.0/main.c  Wed Apr 25 12:00:06 2001
+++ aview-1.3.0-jz/main.c       Sat Aug 24 23:43:03 2002
@@ -52,6 +52,7 @@
+    system("xwd -silent -out curframe.xwd -nobdrs -name 'aa for X'");
diff -Nru aview-1.3.0/ui.c aview-1.3.0-jz/ui.c
--- aview-1.3.0/ui.c    Wed Apr 25 12:04:37 2001
+++ aview-1.3.0-jz/ui.c Sat Aug 24 23:42:17 2002
@@ -204,7 +204,8 @@
            resized = 0;
-       c = aa_getevent(context, 1);
+        quit = 1;
+       //c = aa_getevent(context, 1);
        switch (c) {
        case 'h':

The next step was to use my patched aview (aview.xwd) to convert each frame to an image of text. I did this with a small script.


export PHASEONE=/tmp/matrix/phase1
export PHASETWO=/tmp/matrix/phase2

convert-sequence ()
    cd $PHASEONE
    for FRAME in `seq -f %08g 1 196158`
        while [ -e $PHASEONE/pause ]
            sleep 300
        echo $FRAME
        convert -quality 100 -crop 720x360+0+60 $IMAGE temp.jpg
        if [ $? -ne 0 ]
            echo error in initial cropping
            exit 1
        jpegtopnm temp.jpg >curframe.ppm 2>/dev/null
        if [ $? -ne 0 ]
            echo error converting cropped image to ppm
            exit 1
        aview.xwd -width 135 -height 57 -dim -bold -reverse -normal curframe.ppm
        if [ $? -ne 0 ]
            echo error with aview
            exit 1
        convert -colorize 83/1/100 -crop 1080x720+0+10 -geometry 720x480 curframe.xwd $PHASETWO/$IMAGE
        if [ $? -ne 0 ]
            echo error with final convert
            exit 1
        mv $IMAGE converted/
      rm -f temp.jpg curframe.ppm curframe.xwd

echo -e "`date`\tStart" >>$LOG


echo -e "`date`\tFinished convert-sequence" >>$LOG

"----------------------------------------------------------------------------" >>$LOG

At this point I had a folder filled with my ASCII images. I wanted to combine them together to make an MPEG-2. I ran into several problems.
jpeg2yuv can not read all of the jpeg' was just for testing, not for production.
ppmtoy4m can *not* read pgm files, only *true* ppm files.
ppmtoppm can not be used in a stream with multiple files.
I did not have the hard drive space to hold all of these images as bitmaps.

The solution that I chose:
Convert the images to bitmaps and compress with bzip2.
Decompress the images in RAM and convert to MPEG-2.

for FRAME in `seq -f %08g 1 196158`
    echo $FRAME
    jpegtopnm ../phase2/$FRAME.jpg|ppmtoppm|bzip2 >$FRAME.ppm.bz2
I did not have any one drive large enough to hold all of these images. I made a text file that listed the location of each image, in order. To combine these images into an MPEG-2 I ran:
time cat /tmp/matrix/list|xargs bzcat|ppmtoy4m -F 24000:1001|mpeg2enc -f 8 -q 7 -F 1 -a 3 -4 1 -2 1 -P -I 0 -N 0 -o video_DVD.m2v

time cat /tmp/matrix/list
time, because I want to know how long it takes...

cat the list of images needed because it is the easiest way (the images are on different drives)

xargs bzcat
xargs so bzcat will uncompress as many images at possible in as few instances as possible

ppmtoy4m -F 24000:1001
convert ppm files to y4m movie with the correct ending frame rate

mpeg2enc -f 8 -q 7 -F 1 -a 3 -4 1 -2 1 -P -I 0 -N 0 -o video_DVD.m2v
-f 8 DVD MPEG-2
-q 7 Minimum  quantisation  of the output stream. The lower the number the
higher the quality
-F 1 24000.0/1001.0
-a 3 16:9 display
-4 1 controls  discarding during  the  initial  4*4 sub-sampled search 
-2 1 controls discarding during the secondary 2*2 sub-sampled stage
-P forces the GOP size selection  to  choose  sizes that ensure 2 B frames
appear between adjacent I/P frames
-I 0 support for interlaced video turned off
-N 0 reduce the precision with which of high-frequency information encoded
-o video_DVD.m2v out file = video_DVD.m2v

That took 892 minutes and created my MPEG-2 video:

7465361053 Nov 19 15:24 video_DVD.m2v
I added sound with:
time mplex -S 0 -f 8 -M -V -O 101 -o The.Matrix-ASCII.mpg video_DVD.m2v /tmp/matrix/matrix.ac3
That took 9 minutes and created my high quality The.Matrix-ASCII:
7989979136 Nov 19 16:57 The.Matrix-ASCII.mpg

That would have been the end except I wanted to share this. BitTorrent was the way that I chose to distribute the movie. I wanted this to fit on a DVDR. That meant shrinking the movie. I had plans of making a menu and maybe adding some screenshots of the scripts running. I used CCE with a max vbr rate of 9800 and an average of 4110. After 1 meg of overhead I was left with one meg free on the DVD+R. I left the movie alone at that point, being the highest quality that would fit.

I wanted a nice image to stick on the DVD. I thought that I might as well do the insert as well. I scanned those two images in and converted them to ASCII:

aview.xwd -width 200 -height 121 -extended -dim -bold -reverse -normal dvdbig.pnm
aview.xwd -width 492 -height 191 -extended -dim -bold -reverse -normal front.pnm


Return to The.Matrix-ASCII main page.