Author Archives: tommychheng

About tommychheng

I write a tech blog at

Self-Publishing Tools for converting an Ebook to a Paperback

I self-published The Non-Technical Guide to Web Technologies as an ebook via Amazon Kindle store about half a year ago. After many requests for paperback copies, I decided “why not” also try self-publishing the book? I looked around for various self-publishing tools but settled on Amazon’s

I already had a cover from the ebook, but i still needed a spine/backcover in the right format. I used fiverr to get a few versions. The starting prices are $5 at fiverr but you’ll generally spend more for the “extra” services like having a PSD format for the cover.

Createspace was very easy to use. Just type in information and upload the files. They were able to create and ship the proofs quickly.

After approving the proofs, they were in the Amazon store in a few days. It also automatically links up with the Kindle edition.

book cover for non-technical guide to web technologies

I’m very impressed by today’s tools to get things self-published. I highly recommend using the combination to convert your ebook to a paperback.

Encode OpenGL to Video with OpenCV

I needed to create a working command line demo application of piping an OpenGL rendering into a video file. This experiment is intended to be just proof of concept and be a very naive implementation.


The main steps are:

  • OpenGL rendering
  • Reading the rendering’s output
  • Writing each output frame into the video

This guide will cover an OpenGL >4.0 application tested on a Mac OS X. It should be portable to Linux/Windows as well.

If you just need to create an OpenGL output only on iOS, the AVFoundation classes will make this process much easier. Additionally, if you need to only use Android (API 18), you can use MediaMuxer to also easily output an OpenGL rendering to a video file. See for details.

OpenGL Rendering

The focus of this article isn’t on the OpenGL rendering logic, so let’s just go with a basic OpenGL application which renders a sliding window across an image texture.

The basic structure of our app will be:

(See complete source code on Github)

Reading the Rendered Output Frames

After you draw to the window, we use glReadPixels to read the pixel data from the OpenGL frame buffer into a block of memory. ( Alternatively, you use OpenGL Pixel Buffer Object for more efficiency )

unsigned char *raw_image = (unsigned char*) calloc(width * height * 3, sizeof(char));
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, raw_image);

Writing the output frames into a video format

Let’s start by setting up the OpenCV Video Writer:

CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 30;
int width = image_width;
int height = image_height;

writer = cvCreateVideoWriter("out.avi", CV_FOURCC('D', 'I', 'V', 'X'), fps, cvSize(width, height), isColor);

You can change CV_FOURCC('') to CV_FOURCC('X', '2', '6', '4') for x264 output. Make sure you compiled ffmpeg with x264 support and OpenCV with ffmpeg.

We then create an OpenCV IplImage from this block of memory. Finally we just use OpenCV’s cvWriteFrame to append the frame to the video output.

IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
img->imageData = (char *)raw_image;
cvWriteFrame(writer, img); // add the frame to the file

You will need to read the framebuffer and write to the video using OpenCV on every frame update.

After you are done writing the frames to video, be sure to release the OpenCV video writer.


The alternatives to using OpenCV for video writing are using the C libraries of ffmpeg or gstreamer or libx264(mp4)/libvpx(webm) directly. These would require the RGB image data be converted to YV12 (or YUV420) color space first.

This Stackoverflow post goes over the details of using the x264 C api

Sample Project

I posted an example project on GitHub which demonstrates how this works:

Don’t Imagine Success, Make an Actionable and Trackable Plan

I’m in the process of reading 59 Seconds which relies on scientific research to debunk common self-help advice.

One common self help advice you may have heard is

“imagine success and you will be successful”

The author, Richard Wiseman suggest the better alternative is to actually create an actionable and trackable howto plan. A howto plan is simply just writing out your goal along with sub goals as a step by step process. Each sub goal must be trackable and time-based.

For example, if you want to “Find a new job”, a possible plan can be:

  • Week 1: Write or update resume
  • Every 2 weeks for Next 6 Months: Apply to a job.
  • Keep a journal of each job application and its status.

This is a simple idea but much better alternative than just wishing and imagining success.

The Non-Technical Guide to Web Technologies Ebook Published!

After a few months of writing, editing and testing with lots of readers, I’m releasing The Non-Technical Guide to Web Technologies ebook. It’ll be available as a PDF and Amazon Kindle format.

It’s roughly 60+ pages of concise text, diagrams and images to help teach the basics of web technologies. I spent a lot of time going and back forth finding the right balance point of how much detail to include.

In the book, I cover things everyone in a technical company should be aware of:

  • How a web page gets to your web browser.
  • Common software development questions.
  • HTML5, JSON, AJAX explained.
  • The programming languages and databases used to create web applications.
  • The different types of servers used.
  • The different software engineering job titles in a internet companies.
  • Common Security attacks.
  • The web technologies used by a few internet companies: Etsy, Pinterest, Square, Instagram, Tumblr.

This book will cater to the non-programmers(startup founders, recruiters, sales, business development, marketing) interested in learning more about the field without actually learning to code.

The Non-Technical Guide To Web Technologies
Read a copy now!

Thanks to Jared Cohen @jaredcohe, Joe Mahavuthivanij @epicsaurus, Tony Tran @quicksorter for the EXTENSIVE proof reading and feedback!

Thanks for the support everybody, it has been on Amazon’s Best Sellers List for “Computer and Technology” in the past week. Below Walter Isaacson ‘s biography of Steve Jobs and Steven Levy’s The Plex (Google) book, but still in the top 10. :)

Amazon's Best Sellers in Computer and Technology

Hosting a Static Website on Amazon S3

So you need to setup a static web site for a friend/customer with a cost-effective and low maintenance solution?

The best solution I found is Amazon S3. Amazon S3 charges $0.095 per GB and $0.01 per 10,000 GET requests. For most sites, this is practically free. There is also no server you need to login so this is a very low security risk.

To host a static web sie on Amazon S3, follow these steps:

Get a Domain Name

I prefer to use

Namecheap domains

Create an account

Sign up for an AWS Amazon account
You will get an access key and a secret key.

Setup your s3 bucket

Click on S3. Click on create bucket. Name this bucket after your domain name with a “www” prefix:

Enable the “Website hosting” option. You can select which region: us-west-1, us-east-1, etc.

S3 link


Set your DNS records

On your domain page, add a CNAME record “www” and point it to

Add a CNAME in Namecheap

Upload your files

Upload your files from the S3 bucket UI.

Upload in S3 Console

Visit the site

That’s it!

If it shows a permission denied, make sure the permissions are set for public.

Alternative upload methods

Alternatively you can upload using a native application like Cyberduck to upload your files.