Saturday, August 26, 2017

Build system comparison for C shared library: Manual vs. Makefile vs. Bazel

Here is a simple code for shared library (.so) and an executable that uses it:

Library Source files (libhello.c and libhello.h):

Source for the executable that uses the above library (main.c):

There are many ways to build and execute these sources. Lets look at three of them. The first one is a collection of manual commands that you need to execute in a particular order. The other two uses some form of build system. Before you proceed, make sure to have the C compiler installed on your Ubuntu PC. To do this, execute the following at the command prompt:

sudo apt-get install build-essential git

Manual build:

Place the three source files in the same directory. Open the command prompt, switch to the same directory and execute the following commands to compile, execute and clean:
  1. Compilation
    1. Compiling the library sources into object files with Position Independent Code:
      gcc -c -Wall -Werror -fpic libhello.c
    2. Creating a shared library from an object file
      gcc -shared -o libhello.o
    3. Linking with a shared library
      (prefix "lib" will be automatically added to library name, -L is used to specify search folder)
      gcc -L$(pwd) -Wall -o main.exe main.c -lhello

      if there are any issues, use the command to debug linker: ld -lhello --verbose
  2. Running the executable
    1. Making the library available at runtime
      export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
    2.  Run the binary
  3. Cleaning
    1. Execute:
      rm -rf *.o *.so *.exe

Building using Makefile:

Place the three source files in the same directory. Also create and place a new file "Makefile" with the following contents in the same directory:

Open the command prompt, switch to the same directory and execute the following commands to compile, execute and clean:
  1. Compilation
    • make all
  2. Running the executable
    1. Making the library available at runtime
      export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
    2.  Run the binary
  3. Cleaning
    • make clean

Building using Bazel:

To use Bazel (The build system from Google), you need to first install it. Do so using following commands:

  1. Install JDK 8
    • sudo apt-get install openjdk-8-jdk
  2. Add Bazel distribution URI as a package source (one time setup):
    • echo "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
    • curl | sudo apt-key add -
  3. Install and update Bazel
    • sudo apt-get update && sudo apt-get install bazel
Next, create a directory structure like so:

Current folder
├────WORKSPACE (Blank file)

└───main (folder)
     ├───BUILD (Bazel build script)

The content of the BUILD file should be as follows:

Now carry out the following commands to build the file using Bazel from the command prompt after changing to the directory with blank "WORKSPACE" file:
  1. Compilation
    • bazel build //main:all
  2. Running the executable
    • ./bazel-bin/main/main.exe
  3. Cleaning
    • bazel clean
Compiling, running and cleaning using Bazel

Output files created in the working directory by Bazel
By default, (when linkstatic option is not specified in BUILD file), Bazel links libraries to executables statically. To disable that, specify linkstatic = 0

Monday, July 17, 2017

My favourite alias in .bashrc on Ubuntu

Colorizing and handling system/kernel logs
  • alias logread='cat /var/log/syslog | ccze -A'
  • alias logclear='sudo truncate -s 0 /var/log/syslog'
  • alias logsave='cat /var/log/syslog | ccze -h > ~/log.html'
  • alias dmesgread='dmesg | ccze -A'
  • alias dmesgclear='sudo dmesg -c'
  • alias dmesgsave='dmesg | ccze -h > ~/log.html'
You will have to install ccze (sudo apt-get install ccze)

Thursday, July 13, 2017

Replacing batteries in Black and Decker DP240 2.4V Direct-Plug Rechargeable Screwdriver

I have owned a Black and Decker DP240 Cordless Electric Screwdriver for 5 years now. Its battery had started losing its capacity to hold charge, so I looked online to see if it was possible to change its batteries. I couldn't find any blog/DIY guide on which batteries to replace the internal ones with and how to go about pry open the screwdriver and putting it back. So here are some photos outlining how I changed the batteries in mine and turned it into new.

To open the screwdrive, you will need a set of "Torx Pin 6 lobe" screwdriver set. You cant use regular torx screwdriver bits. You need ones with holes in the center of the bits so that the center pin on the screw can fit into those holes. You can buy just a set of just the bits here.

Torx pin 6 lobe Screwdrivers to open the shell

Screwdriver with the shell opened

It seems that the screwdriver comes with two AA size
1.2V NiCd 800 mAh cells installed

I replaced the 800mAh batteries with 2550 mAh NiMH cells
eneloop by Panasonic is the best brand of NiMH cells

Soldering wires onto the cells

And putting the screw driver back together

Thursday, May 11, 2017

Come C tricks

Swapping the values of two variables with out using a third!!
x = x ^ y;
y = x ^ y;
x = x ^ y;
All hail the XOR operation

int c;
c &= (c-1);
check if c == 0

This allows you to check if C is a power of 2 (i.e. 0,1,2,4,8...)

Reading sentences (including spaces) from stdin:

scanf("%s",str); can't read spaces in input string.
To do that, you have to: scanf(" %[^\n]s",str);

Note the space before % within the quotes.


Monday, May 1, 2017

Set Elon's latest tweet as your desktop wallpaper

If you have an Ubuntu box, you can use a script to to set your wallpaper's to Elon's Latest Tweet.

Here is how you setup:
  1. Install required packages.
  2. Download - an OAuth based twitter client implemented completely as a bash script.
  3. Get Token keys for from your Twitter account and save it in the config file. You need this for OAuth that uses.
  4. Get a free account on and fetch your API keys. This service allows you to generate screenshot of any supplied URL - you can use this service to to fetch PNGs's of Elon's tweets. We do screenshots because aren't just interested in tweet's text but also any images that Elon chooses to attach with his tweets.
  5. In the batch script ( appended below, configure the pages2images API key
  6. Setup the batch script ( as a cron job which runs once every minute.
You can set this script up on a Raspberry Pi running Raspbian connected to your TV as well. Its always nice to have some inspiration trickling in while you work.

Here is how my desktop looks like
Here's how to go about putting the pieces together:
  1. Open a terminal window and install the required software on your ubuntu box:
    sudo apt-get install jq imagemagick pngcrush nkf
  2. Clone and place and tweet.client.key in your home directory
  3. While logged into Twitter, visit and create a new app and generate the required Token and Keys and place them in tweet.client.key
  4. Mark as executable:
    sudo chmod +x
  5. Register on and get your API key
  6. Create a new script called in your home folder and copy and paste the code snippet appended below.
  7. Edit and insert the pages2image API key at the appropriate location.
  8. Mark as executable:
  9. Set the script to run once every minute:
    crontab -e
    and insert the following line:
    * * * * * bash ~/
The script will run once every minute and will check if there is any new tweet from Elon since last check. If there is, it will submit the URL for screenshot generation and exit. When the script is run again at the next consecutive minute, it will fetch the image, crop it and set it up as wallpaper. If Elon has put up a new tweet, the URL of this new tweet is submitted for screenshot and the script exits. In such situation, you will miss out the 2nd tweet if the time difference between 1st and 3rd tweet is less than 2 minutes - this can be fixed in the script, but it seemed to be a bit much. Thank God Elon doesn't go crazy on twitter. All the tweets are saved in the Pictures folder.

Tweet screenshots are saved in Pictures folder
This is what the cropped tweet looks like

This is what the cropped tweet looks like

Wednesday, April 26, 2017

Classroom Timer V1

If you have ever been a teacher at any point in your life, you would have realized the importance of keeping your students engaged and on task at all times during the short period every day that you get to spend time teaching them. If you have just 30 minutes per day, you want to maximize the learning by having a structured lesson plan that moves smoothly from Introduction to New Material to Guided Practice and into Independent Practice. And if you have planned for the lecture properly, you would know how much time you want to spend at each stage doing each activity with the kids to ensure that the lesson is completed on time and doesn't spill over onto the next lecture.

You may have a clock in your class, but having a countdown timer makes more sense in competitive and group activities. When the kids see the time ticking down, and they rush to try to finish the activity on time, it can give them an adrenalin rush and bring excitement to the activity.

I am an engineer by profession and passion. So during as a fellow at Teach For India, I was always looking for ways to enhance teaching through use of technology. And so I made a small classroom timer based on Arduino. The first version had a dot matrix display and switches. Soon, I figured that adding WiFi and controlling the timer using a mobile phone would allow the time to be permanently installed above the blackboard in the classroom and avoid the need to touch the timer repeatedly and hence avoid any breakage due to accidentally dropping the timer.

The first version based on Arduino UNO and 8x8 Matrix display
For the first version I used an Arduino UNO along with a 4 panels of 8x8 LED Matrix Displays. The left most 2 displays displayed the time remaining in minutes and the right most two displays were for the two digits which reported the seconds remaining. These display modules are powered by MAX7219 which allows you to control the displays using just 3 pins of the Arduino UNO. I connected the pins 2,3,4 of Arduino UNO R3 respectively to the DataIn_Pin, Clock_Pin, Load_Pin of the 4 module display. I powered the device using a portable power bank and put everything in a box. There are four switches connected to pins 8, 9, 10 and 11 of the Arduino which allows you to start / pause / stop the countdown as well as set the time that you want to countdown from in increments of 30 seconds.

There are four switches. When you power up the timer, it starts counting down from 1:00 (1 minute). You can pause this by pressing the stop button once, and continue the countdown when you press start button. If you press stop twice, the timer is reset to the last set value (1:00 by default). When the timer is stopped (press stop twice), you can use the up and down buttons to set a new reload time. Once you have set the time, you can press start to start counting down. the switches are wired in active low mode. There are pullups enabled on the 4 points. I have also added external pullup resistors. When the switches are presses, they short the corresponding arduino pin to ground.

Here is a video and photo of the internals:

The first time I set about assembling the device, I used a plastic box. Soon after the plastic box broke and the power bank mal-functioned and so I got a switch box and transferred all the circuitry to the new box. the new box was sturdier and looked neater!

Classroom Timer V1 in a better box


I have made use of the following 3 libraries:

  1. TimerOne - for using a Timer Interrupt to update the display once every second.
  2. LedControl - This one is used for interfacing to MAX7219 displays. I had to modify this library because I used the modules upside down.
  3. PinChangeInt - Since the 4 buttons are connected to interrupt pins, I have sued Pin Change interrupts to respond to button presses. 
Many of these libraries are continuously updated, and the newer version might not work with my existing code. Also I had to modify LedControl library as mentioned above - so I have created a github repository for the code as well as a library here:
In case you want to use the code, download the 3 library folders to your Documents\Arduino\libraries folder, then download the .ino file and put it in a new folder on your computer. make sure this folder has the same name as the .ino file. double click on the .ino file and use Arduino to download the code onto your Arduino UNO R3.
The ClassroomTimerV1.ino file is present in the github repo above and is also embedded as a gist below:

Tuesday, April 25, 2017 on LinkIt Smart 7688 Duo (OpenWrt)

Temboo-less tweeting from the shell

LinkIt 7688 Duo is a cheaper ($15.9 vs $74.95) and breadboardable version of Arduino Yun. Arduino Yun comes preloaded with Temboo whereas LinkIt does not have that preloaded. Temboo is a great go between service that allows your IoT project to talk to existing services like google drive, twitter or dropbox - but to do anything long term and meaningful with it, you have to upgrade from a free temboo plan to a paid plan - Arduino Yun is already expensive and this makes it even moire expensive. I used Arduino Yun and Temboo to make a shimmering lamp that reacts to tweets from your sweetheart - But now it was time to move on to better yet cheaper builds.

A Raspberry Pi running Node Red can achieve a lot but here I want to focus on LinkIt because I am using it as a part of a larger "art" project. Since LinkIt has an AVR microcontroller (Arduino programmable over WiFi and Arduino Bridge), it allows for greater flexibility in interfacing to sensors and modules via the microcontroller. Also, until someone (or me) ports Node Red to OpenWrt platforms, I would prefer to use bash scripts and Arduino code to get my bidding done.

So one of the first things on my agenda was to figure out a Temboo less way of fetching tweets. What is outlined below is how I got (which is a bash script to fetch tweets)to work on OpenWrt - more specifically LinkIt 7688 Duo. For this, we wont be writing any Arduino code since the Microcontroller does not come into play (yet). But what we will be doing is playing around with bash scripts and cross compiling 2 packages for OpenWrt.

My LinkIt 7688 Duo as a part of a larger project.
The LinkIt is the one in the middle. The one on a bottom is a 5V powersupply.
And the one on top is a dimmer circuit - similar to the one I used in my twitter lamp project

Step 1 - Cross compiling packages required by

Since is just a bash script, it requires certain packages to exist on your system. They are curl, jq, nkf, openssl. Of these openssl and curl can be installed on your LinkIt since they are a part of the OpenWrt repositories. But jq and nkf - these you will have to cross compile on a Linux PC and transfer them to LinkIt.

Here are the steps to make sure you have all the packages required by on your LinkIt:

  1. Connect your LinkIt to your home's WiFi network - check this
  2. Figure out your LinkIt's IP address - there are many ways to do this:
  3. Using my router's page to figure out the IP addresses of my 2 LinkIts connected to my home network.
    The MAC addresses of LinkIt begin with 9e:65:f9
    (Yes I have OpenWrt installed on my home router as well)
    Using Arduino IDE to figure out the IP addresses of LinkIt
    1. You may need to log on to your WiFi Router's page from your PC and look at the list of devices and IP addresses.
    2. You can install Arduino on your PC, add support for LinkIt 7688 Duo and then wait for a few moments till Arduino automatically discovers the LinkIt. Then you can look under Tools>Ports
  4. Use PuTTY to login to your LinkIt 7688 Duo. Login will be "root" and password would be whatever you set during the getting started stage.
  5. Lets install the basic packages that are required and available - execute the following commands on LinkIt over PuTTY:

    opkg update

    opkg install ip curl openssl bash nano grep getopt bc ca-certificates 
  6. We still need to install nkf and jq. For that, we will need to use a Linux computer - preferable one running Ubuntu and perform the following steps (on your Linux PC not LinkIt):
    1. Download OpenWRT SDK for Linux from here onto your x64 Ubuntu Laptop. (I used Ubuntu 15.10 x64 on a VirtualBox Virtual Machine - I used a virtualbox image from
    2. Extract the folder to your home folder:
      tar -xvf OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-
    3. Install some required build tools on your Ubuntu PC:
      sudo apt-get install autoconf build-essential
    4. Set the environment variables:

      export PATH=~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-$PATH

      export STAGING_DIR=~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-
    5. Change to ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc- :
      cd ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-
    6. Create two folders here:
      mkdir jq
      mkdir nkf
    7. Create the makefile for jq and place it in the jq directory that you just created. (Appended Below):
      gedit jq/Makefile
    8. Create the makefile for nkf and place it in the nkf directory that you just created (Appended Below)
      gedit nkf/Makefile
    9. Go back to ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-
      cd ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-
    10. And issue the make command:
    11. cd to the ourput directory:
      cd ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-
    12. You will find the two .ipk files:
    13. Copy these two ipk files to your LinkIt 7688 duo. you can do this in many ways but the best way is to use scp protocol. In my case I simply copied the files from my Ubuntu Virtual Machine to my Windows machine and used WinSCP (Make sure file protocol is set to SCP) to login into my LinkIt and copied the .ipk files to the /root folder there.
    14. Issue the following commands to install jq and nkf on your LinkIt (Issue commands over PuTTY while in /root directory):
      opkg install jq_1.5_ramips_24kec.ipk
      opkg install nkf_2.1.4-1_ramips_24kec.ipk
    15. And you are done with installing the required packages
Here are the Makefiles for cross compiling jq and nkf

Makefile for nkf:

include $(TOPDIR)/





include $(INCLUDE_DIR)/

define Package/nkf
  TITLE:=Network Kanji code conversion Filter (NKF)

define Package/nkf/description
  Network Kanji code conversion Filter (NKF)

  prefix="$(PKG_INSTALL_DIR)" \
  MKDIR="mkdir -p"

define Package/nkf/install
 $(INSTALL_DIR) $(1)/usr/bin
 $(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/nkf $(1)/usr/bin/

$(eval $(call BuildPackage,nkf))

Makefile for jq:
#jq is written in C and has no runtime dependencies, so it should be possible to build it for nearly any platform. Prebuilt binaries are available for Linux, OS X and Windows.
#The binaries should just run, but on OS X and Linux you may need to make them executable first using chmod +x jq.
#jq is licensed under the MIT license. For all of the gory details, read the file COPYING in the source distribution.

include $(TOPDIR)/



PKG_FIXUP:=autoreconf -i

include $(INCLUDE_DIR)/

define Package/jq
  TITLE:=jq json interface

define Build/Compile
 $(MAKE) -C $(PKG_BUILD_DIR) CFLAGS=-msoft-float

define Package/jq/install
 $(INSTALL_DIR) $(1)/usr/bin
 $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/jq $(1)/usr/bin/

$(eval $(call BuildPackage,jq))

Step 2 - Cross compiling packages required by

Next we need to get onto LinkIt and configure it.
  1. Visit download and tweet.client.key to your PC and transfer it to your LinkIt using WinSCP. You can also download the two files directly to your LinkIt by issuing 2 commands over PuTTY:
    curl -O
    curl -O
  2. Mark as executable:
    chmod +x
  3. Now we need to configure the keys and add them to tweet.client.key on LinkIt. Visit and login to your twitter account.
  4. Next open a new tab in the same browser and visit
  5. Click on "Create New Apps"
  6. Enter something in Name, Description and Website
  7. Accept the Developer Agreement and click "Create your Twitter Application"
  8. Now click on your newly created application and click on "Keys and Access Token"
  9. Open tweet.client.key over WinSCP and copy and past key from the webpage to tweet.client.key
    1. Enter your twitter handle next to MY_SCREEN_NAME=
    2. Enter "en" next to MY_LANGUAGE=
    3. Copy the string mentioned next to Consumer Key (API Key) to CONSUMER_KEY=
    4. Copy the string next to Consumer Secret (API Secret) to CONSUMER_SECRET=
    5. Copy Access Token to ACCESS_TOKEN=
    6. Copy Access Token Secret to ACCESS_TOKEN_SECRET=
    7. Click save
Editing tweet.client.key
The original is published at but I had to fork it and make some modification to it so that it would run on OpenWrt. I have forked it at and that's what we have used. (Modifications involved creating symbolic links to stdin and stdout in proc file system - these are lacking by default in OpenWrt)

Finally everything is set and we can test our setup by fetching the latest tweet from - say - elonmusk, piping it through jq and printing only the unique tweet id and the text of the tweet itself:

./ search -q "from:elonmusk" -c 1 | jq '.statuses[0].id, .statuses[0].text' running in a PuTTY window with Twitter open in Google Chrome

Thursday, April 20, 2017

Dealing with WiFi IP Cameras and .264 files

On a recent visit to China, I purchased a cheap IP camera which looks like a robot:

You can get one online from amazon for twice the amount that you might pay for it when you buy it from one of the shops in ShenZhen (I got it for around 150 CNY or 1500 INR). The camera is supposed to be installed in your house where you can configure it to connect to your home's WiFi router. That way you can connect to the camera from anywhere in the world (using your web browser or smart phone app) and watch and hear what ever the camera picks up. Here are some of the features of this camera:

  • Tech Specs (you can find these on the amazon page as well, although the model might say something else)
    • Model: The packaging for my camera said "Mini Robot Wireless Camera H811 IP Camera"
    • Power: DC Input 5V 2Amps (via microUSB connector)
    • Image quality: 960P 1.3Megapixel
  • WiFi:
    • Out of the box, the camera defaults to WiFi master mode (i.e. wifi hotspot) . This is so that you can use the app on your smartphone to connect to it and if required, you can configure the camera to switch to client mode and connect to your home's WiFi router.
    • By default, when you look for it, the SSID of the WiFi signal emitted by the camera would be something like: "HSL-337026-GDDEN"
    • The default WiFi WPA2 key is 0123456789
    • Android app:
      • The app for your smart phone is called NetCam (Google Play Store link)
    • Computer:
      • In case you connect to the camera using a laptop, punch in the following URL into your web browser:
      • It will ask you for login credentials, enter "admin" as login and leave the password blank.
  • Reset button and microSD card slot:
    • The camera has a microSD card slot on the back. If you install a microSD card, the camera will also record the video (only video no audio) onto the SD card.
    • The small hole next to the camera on the back is for resetting the camera in case you forget its login password (this is separate from the WiFi password)
  • Physical structure:
    • The bottom part of the camera is made of iron and the camera head itself has a magnet in it. This allows you to screw in the bottom of the camera wherever you want and them attach the camera head and orient it in any direction you want.
    • The bottom of the camera also has a QR code which you can scan with your smart phone app to connect to it for the first time. The QR code has the WiFi Master SSID encoded into it.

So what did I do with the camera? I mounted it in my car as my dashcam. The problem is that the camera does not have a battery backed real time clock (RTC) and there is no internet (which would have helped re-sync the clock because the camera supports network time protocol or NTP) in my car so the camera does not maintain the time when I turn off the car (and power to the camera is cut). I use a 2 amp 5V smart phone charger that plugs into my cigarette lighter to power the camera. I could have connected the camera directly to the 12V battery and that would have ensure that the camera ran continuously and never lost time, but then my car battery would get drained as well.

I installed the base (made of iron) of the camera onto my rear view mirror and the camera heat got attached to the base thanks to the magnet present inside the head.

About RTC and NTP:
As mentioned above, this camera does not have any battery (neither Li-ion or coin cell) to main clock when the car is turned off. The camera can act as a WiFi client and can synchronize its time at boot up using an NTP server. But for I would need to get an internet connection for my car - possibly a 3G/4G hotspot. In cases where one does not want to do all that, there is a way out. The Global Positioning System is essentially made up of atomic clocks orbiting Earth. We can use a GPS receiver along with a WiFi capable microcontroller and implement the NTP server functionality. There is a tutorial on instructable on how to go about it: - what this instructable allows you to do is to make a small WiFi Access Point (using ESP8266) that doubles up as an NTP server. When you connect your devices (this camera or your smart phone) it would be able to access the internet but you can configure the NTP server address to point to this ESP8266 device and atleast your time synchronization will work. (Another similar project)

About handling the .264 media files on a Windows desktop
You can connect to the camera using the Android app to watch live video and configure the camera, but there is no way for you to review the video recorded by the camera while the memory card is inside the camera. The android app has no option to playback the recordings. The only way is for you to remove the memory card and insert it into a memory card reader and either connected it to your computer or to your android phone using a USB OTG cable.
The moment you remove the microSD card and insert it into a card reader and attach it to your Windows PC, this is what you see:

The camera fills up the microSD card with equal sized stub files

The camera has filled up the memory card with stub files. The camera starts recording the video into first file. When one file fills up (around 5 minutes worth of video), it continues recording in to the next file in sequence. This ensures that in case the power is cut to the camera (e.g. car accident/break in), atleast the last file would have been saved properly and would help in investigation.

Playing back on Desktop:
You can use VLC Media Player to play these .264 files. You have to make a small change in the settings:

  1. Select View>Preferences
  2. Switch to "All" under Show Settings
  3. Click on "Demuxers" under Input/Codecso
  4. Select "H264 video demuxer" from the drop down list and click Save
  5. Now you can drag and drop .264 files into VLC media player and play them back
  6. Make sure to change the Demux module setting from "H264 video demuxer" back to "Automatic" once you are done with playing .264 files. This will allow you to play your regular video files correctly.
Here are the screenshots to clarify the above steps:

You will note that when playing .264 files, you don't hear any audio. I am not sure if the camera records audio or not but, according to what I have read in discussion forums, no one has gotten any audio playback from these raw H264 format video files.

Converting videos on Desktop:
In case you want to convert the video to mp4 format, there are two steps that you have to follow:

  1. Use ffmpeg to convert the .264 file in to raw uncompressed AVI file. This will take care of stream errors which usually creep in when the power supply to the camera (like in a car) is not reliable or when the camera experiences vibration.
  2. Use ffmpeg to convert the uncompressed file to mp4

Here are the steps in the conversion process:
  1. Visit and download the latest stable, static 32bit version.
  2. Unzip the file into a folder on your computer.
  3. Move your .264 video file into the bin folder of the ffmpeg folder
  4. Open a command prompt and cd to the ffmpeg/bin folder
  5. Issue the command ffmpeg -i apf00047.264 -vcodec rawvideo -y output.avi
    This will begin converting the file apf00047.264 into a raw uncompressed file.
    During the conversion process, ffmpeg will display a number of messages about finding errors in the stream and compensating for it. Once the conversion process is done, you will realise that the 64MB file has been converted to an .avi file occupying 6.8 GB of space. You can try playing this file in VLC player (make sure to set Demux module back to Automatic)
  6. Finally you can convert the uncompressed avi file to mp4 format using the command:
    ffmpeg -i output.avi output.mp4
    Once that is done, you can delete the output.avi uncompressed video file. The output.mp4 video file can be uploaded to Youtube and Facebook if required. The .mp4 file can also be played using VLC player. It of course wont have any audio - that's the issue of the camera. The output.mp4 would be around 107 MB in size.
Here some screenshots outlining the above steps:

Downloading the ffmpeg utility for Windows

Copy your .264 video file to the bin folder within the extracted ffmpeg folder

Opening a command prompt and navigating to the ffmpeg's bin folder

Issuing a command to start conversion of .264 to uncompressed .avi format
ffmpeg spews messages regarding stream errors while creating uncompressed .avi file
The uncompressed output.avi file is huge - 6.8 GB
You can play the uncompressed output.avi in VLC Player

Executing ffmpeg a second time to convert uncompressed .avi to .mp4 format

Playing output.mp4 in VLC Player

Playing back on Android Phone:
You can use a USB OTG cable along with a card reader to connect the microSD card to your android phone. Once you do that - and if your phone supports USB OTG - a notification will pop up allowing you to explore the files on the microSD card. Now you can use this file explore feature and long press the .264 file that you are interested in to select it. Once selected, copy it to your phones internal memory. Then start the MX player app. The MX player (Free version with ads | pro version) app scans the phone's memory for video files, and this .264 file will show up as well. Just tap on it and the video will start playing.

Use the OTG Cable to connect card reader to the Android phone.
Explore the file using Android's builtin feature an copy the files to phone's internal memory.

MX Player app shows the recently copied .264 video file.

Tap on the file to play it.