September 18, 2010

Daystar Learning Center

Posted in Uncategorized at 3:44 pm by dgcombs

It started off simply and innocently enough, with this email subject line: “A huge favor” from my dear friend, Rowena. Inside the email, she asked, “Would you kindly consider filling in?” Oh, sure, I though. A six-month stint calling children to their weekly classes and perhaps even teaching once in a while. No problem.

It turned into a seven year long commitment that would find me enjoying one of my favorite things, teaching children. If you’ve never tried it, I highly recommend it. It keeps you young. And I learn new things. All the time. I was cleaning out Daystar bag where I kept my reference manual for children’s education full of wisdom from ‘Abdu’l-Baha when I realized I was pulling out a lot of my lessons. Almost a year’s worth! I decided to make use of the impromptu attendance sheets on the front.

I haven’t created a video in a long time and decided to take a break from programming JavaScript and Node and learn something new. Perhaps a different source of frustration would be good for me. I decided to create a video of the children who attended my classes, well at least their names.

I sorted the attendance into a delimited file with date and students. Then I struggled over exactly how to make this tabular data into some kind of video. On a whim, I decided to take a quick look at SVG, a distant cousin of XML. To my utter amazement, it was simply a text file! My experience with POV-Ray taught me that you can code almost anything. And my curiosity got the better of me. I decided to take the plunge. After tinkering with a Python script, I had a passable SVG creator that would take my attendance sheet and create a bunch of SVG images.

But how could I stitch these together into a movie? There were well over 350 separate images. Using most tools, that was going to take the one thing I am terribly short on, patience. So rather than tinkering with one single image at a time, I looked for a way to mass import/export/convert them. That’s when I remembered some of the advantages I’d seen in Imagemagick. Using a the command-line convert program I could take those text only .SVG files and create .PNG files from them. And now that I had .PNG files, I could use FFMPEG to pull them all together into a single movie file, dbskids.avi. How hard could it be? Well, I found out.

At that point, it became a mission. I was determined to finish the project without using anything but command-line tools. FFMPEG and ImageMagick are perfect for the job. But they do require some learning. And more learning.

I started off by watching a short video on using FFMPEG from Linux Journal. Clearly a frustrated math major, the video author offered some interesting insights into combining still frames with moving frames to make a finished product. There are two secrets which must be divulged about FFMPEG. It will totally ruin your input image files if you give it an improper command-line. The proper way to link image files together is

ffmpeg -f image2 -i dbskids%03d.png dbskids.avi

There first secret is the “-f image2” command line option. This tells FFMPEG that you are going to use image files and not movie files. But that’s not the killer.

The killer is the “%03d” part. Under Windows and even Linux, when you want to refer to a group of files you use a star “*” or perhaps a question mark “?”. But when using FFMPEG, you use another convention borrowed from C-programming. Here you use a percent to introduce a format, a zero-3 to indicate a three character wide placeholder  and the letter “d” to indicate the characters will be decimal integers. If you use a star in your command, you will find that the first image file is replicated to all the remaining ones and you will have to start from scratch. Again. Oh, no. That never happened to me! My friend, Bob, now, that’s another story.

With the command above, a single image file is a single frame. In North America, our movies are usually running at about 25 frames every second . Even with my glasses on, that’s a little speedy. To slow it down, you can use the “-r <number>” option. This is the frame rate option. Placing it on the input side tells FFMPEG how many times to reuse the single image file in the output. I used “-r 10.” This gave the effect of speeding through the names without being blinding!

The image files needed a little tweaking which I did using ImageMagick’s mogrify and convert. The first task was to add the lovely light blue background to the PNG files. That color, for future reference, is AliceBlue, Teddy Roosevelt’s daughter’s favorite color. To make this work, I used morgify‘s in-place modification feature to change the background to AliceBlue, set the Alpha channel to the background and turn off the Alpha channel altogether:

mogrify -background AliceBlue -alpha Background -alpha off dbskids000.png

As you can see in the command line, the -alpha option is used twice. I thought this was an odd convention, but it worked quite well. ImageMagick uses the concept of an image pipeline, so it acts on the image file one command line operator at a time before it over-writes the old file with the updated version.

I added the text excerpt to the final image file, a collage of a few students, using mogrify/convert‘s draw feature. After studying the official documentation for way too long, I found an article that outlined the steps quite nicely. The full quote is from Baha’u’llah and reads:

“Regard man as a mine rich in gems of inestimable value. Education can, alone, cause it to reveal its treasures, and enable mankind to benefit therefrom.”

The command line used to insert this was pretty simple, but did take a while to perfect:

convert -font Serif -fill dodgerblue -pointsize 30 -undercolor ‘#00000080’ -draw ‘text 40,110 “Regard man as a mine”‘ -draw ‘text 125,220 “rich in gems”‘ dbskids400.png dbskids000.png

There are a few things to note here. The fill color is now DodgerBlue (the stadium, not the uniform) just to see if it works. The undercolor option is a way to create background just for the text. As you can see, this option uses eight numbers rather than the usual HTML six. These last two are the Alpha channel and provides the transparency allowing the underlying picture to peek through. More information on annotations are available from ImageMagick.

Putting the final movie together, I noticed the last image came out awful. In working through the reasons for this, I finally discovered that the trick I used to insert the background color, AliceBlue, in the names had changed the images from RGB32 to RGB24. The missing eight bits are for the Alpha channel. So I used morgrify once again on the final version of the last image to turn off it’s Alpha channel which fixed the problem.

morgrify -alpha off dbskids400.png

And that’s how this little movie got made using command-line components.

The Daystar Baha’i School is now the Daystar Learning Center. It has changed its focus to training children’s class teachers so they can begin their own children’s classes. As The Universal House of Justice wrote in April,

In every cluster with an intensive programme of growth in operation, efforts need to be made to systematize further the provision of spiritual education to increasing numbers of children, from families of many backgrounds – a requisite of the community-building process gathering momentum in neighbourhoods and villages. This will be a demanding task, one that calls for patience and cooperation on the part of parents and institutions alike.

I’m one of the first.


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

%d bloggers like this: