Hunter Ford Hunter Ford

Compiling MP4Box on Mac OS X

# Create a temporary directory for sources.
SOURCES=$(mktemp -d /tmp/XXXXXXXXXX)
cd $SOURCES

# Download the necessary sources.
curl -#LO http://www.ijg.org/files/jpegsrc.v8c.tar.gz
curl -#LO http://downloads.sourceforge.net/project/libpng/libpng15/1.5.1/libpng-1.5.1.tar.gz
curl -#LO http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
curl -#LO ftp://ftp.mars.org/pub/mpeg/libmad-0.15.1b.tar.gz
curl -#LO http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
curl -#LO http://www.libsdl.org/tmp/SDL-1.3.tar.gz
svn export --non-interactive --trust-server-cert https://gpac.svn.sourceforge.net/svnroot/gpac/trunk/gpac

# Unpack files
for file in `ls ${SOURCES}/*.tar.*`; do
    tar -xzf $file
    rm $file
done

cd jpeg-*/
./configure && make -j 4 && sudo make install; cd ..

cd libpng-*/
./configure && make -j 4 && sudo make install; cd ..

cd faad2-*/
./configure --without-xmms --without-drm --without-mpeg4ip && make && sudo make install; cd ..

cd libmad-*/
sed -i -e 's/-march=i486//g' configure.ac
./configure && make -j 4 && sudo make install; cd ..

cd a52dec-*/
./configure --enable-shared && make -j 4 && sudo make install; cd ..

# SDL won't compile on Lion
# http://forums.libsdl.org/viewtopic.php?t=7390&sid=62659329519f407daa486ec8a3ee2ba9
cd SDL-*/
./configure --without-x && make -j 4 && sudo make install; cd ..

cd gpac/
./configure && make lib && make apps && sudo make install lib && sudo make install

Compiling mp4v2 on Mac OS X

# Create a temporary directory for sources.
SOURCES=$(mktemp -d /tmp/XXXXXXXXXX)
cd $SOURCES

# Download the necessary sources.
curl -#LO http://mp4v2.googlecode.com/files/mp4v2-1.9.1.tar.bz2

# Unpack files
for file in `ls ${SOURCES}/*.tar.*`; do
    tar -xzf $file
    rm $file
done

cd mp4v2-*/
./configure && make -j 4 && sudo make install

Compiling FFMpeg on Mac OS X

You must have Xcode installed with Unix Tools. Xcode 3 is available for free via Apple Developer Center. However, Xcode 4 is available through the App Store (free for Lion users).

# Create a temporary directory for sources.
SOURCES=$(mktemp -d /tmp/XXXXXXXXXX)
cd $SOURCES

# Download the necessary sources.
curl -#LO http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
curl -#LO http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.tar.gz
curl -#LO http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
curl -#LO http://pkg-config.freedesktop.org/releases/pkg-config-0.25.tar.gz
curl -#LO http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.2.tar.gz
curl -#LO http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
# curl -#LO http://downloads.sourceforge.net/project/opencore-amr/vo-amrwbenc/vo-amrwbenc-0.1.1.tar.gz
curl -#LO http://www.tortall.net/projects/yasm/releases/yasm-1.1.0.tar.gz
curl -#LO http://webm.googlecode.com/files/libvpx-v0.9.7-p1.tar.bz2
curl -#LO ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
curl -#LO http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
# curl -#LG -d "p=ffmpeg.git;a=snapshot;h=HEAD;sf=tgz" -o ffmpeg.tar.gz http://git.videolan.org/
curl -#LO http://ffmpeg.org/releases/ffmpeg-0.8.5.tar.bz2

# Unpack files
for file in `ls ${SOURCES}/*.tar.*`; do
    tar -xzf $file
    rm $file
done

cd faac-*/
CFLAGS="-D__unix__" ./configure && make -j 4 && sudo make install; cd ..

cd lame-*/
./configure && make -j 4 && sudo make install; cd ..

cd libogg-*/
./configure && make -j 4 && sudo make install; cd ..

cd pkg-config-*/
./configure && make -j 4 && sudo make install; cd ..

cd libvorbis-*/
./configure --disable-oggtest --build=x86_64 && make -j 4 && sudo make install; cd ..

cd libtheora-*/
./configure --disable-oggtest --disable-vorbistest --disable-examples --disable-asm
make -j 4 && sudo make install; cd ..

# cd vo-amrwbenc-*/
# ./configure && make -j 4 && sudo make install; cd ..

cd yasm-*/
./configure && make -j 4 && sudo make install; cd ..

cd libvpx-*/
./configure --enable-vp8 --enable-pic && make -j 4 && sudo make install; cd ..

cd x264-*
CFLAGS="-I. -fno-common -read_only_relocs suppress" ./configure --enable-pic --enable-shared && make -j 4 && sudo make install; cd ..

cd xvidcore/build/generic
./configure --disable-assembly && make -j 4 && sudo make install; cd ../../..

# For Lion, we have to change which compiler to use (--cc=clang).
# If you're building on Snow Leopard, you can omit this flag so it defaults to gcc.
cd ffmpeg-*/
CFLAGS="-DHAVE_LRINTF" ./configure --enable-nonfree --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libfaac --enable-libxvid --enable-libx264 --enable-libvpx --enable-hardcoded-tables --enable-shared --enable-pthreads --disable-indevs --cc=clang && make -j 4 && sudo make install

# --enable-libvo-amrwbenc

# FFMpeg creates MP4s that have the metadata at the end of the file.
# This tool moves it to the beginning.
cd tools
gcc -D_LARGEFILE_SOURCE qt-faststart.c -o qt-faststart
sudo mv qt-faststart /usr/local/bin

Offsite Backup with Backblaze

I take a lot of photographs. And each one of those photographs I save in RAW format to preserve the original integrity and allow me to easily edit the photo in the future.

The byproduct of that is that I need a lot of storage space, and I mean a LOT! Each photo is about ~ 25 MB. Compound that times 100s of photographs I might take at an event, and we're easily talking Gigabytes for one event. Luckily, I have a Mac Pro which lets me keep 4 hard drives with over 3 TB of storage. Two disks are configured as a RAID 0 array for maximum performance. The other two are set up as a RAID 1 array for redundancy, and I use Time Machine to backup the first array.

However, what if my computer were hit with some natural disaster or stolen from my apartment?! I would lose everything regardless if my data was backed up in Time Machine. That's why I signed up for Backblaze.

There are a couple of different services out there that do this, but I think Backblaze does it best. It's dead simple, installs as a lightweight daemon that I've observed uses very few of my precious resources, and does it very cheaply. You can sign up for $5.00 a month or pre-pay for 2 years and get a big discount.

I trust Backblaze because I know their hardware. They blogged about how the built up their storage system.

MongoDB Startup Item for Mac OS X Snow Leopard

Save the following as /Library/LaunchDaemons/org.mongo.mongod.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>org.mongo.mongod</string>
	<key>RunAtLoad</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/bin/mongod</string>
		<string>--dbpath</string>
		<string>/var/lib/mongodb/</string>
		<string>--logpath</string>
		<string>/var/log/mongodb.log</string>
	</array>
</dict>
</plist>

You will need to create a file for the log and a directory for the database.

sudo touch /var/log/mongodb.log
sudo mkdir /var/lib/mongodb

And in a bash session, run the following:

sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod

Setting Up Apache-PHP-Python-MySQL on Mac OS X

  1. Download and install MySQL Package file [MySQL 5.1 for 10.5 (x86_64)]
  2. Install MySQL Startup Item [Howto]
  3. Turn on Web Sharing in System Preferences -> Sharing
    Screen shot 2009-11-29 at 5.19.43 PM
  4. Copy /etc/php.ini.default to /etc/php.ini
    sudo cp /etc/php.ini.default /etc/php.ini
    
  5. Add timezone information to php.ini (PHP will error without this)
    date.timezone = 'America/New_York'
  6. Install php-mcrypt
    1. Download libmcrypt 2.5.8
    2. Build and install .
      ./configure --disable-posix-threads --enable-dynamic-loading
      make
      sudo make install
      
    3. Download PHP 5.3.1
    4. Navigate to php-5.3.1/ext/mcrypt/
    5. Build and install .
      phpize
      ./configure
      make
      sudo make install
      
    6. Add extension to php.ini
      extension=mcrypt.so
      
  7. Install APC
    1. Download PCRE 8.0
    2. Build and install .
      ./configure
      make
      sudo make install
      
    3. Download APC 3.1.3p1
    4. Navigate to APC-3.1.3p1/APC-3.1.3p1/
    5. Build and install .
      phpize
      ./configure
      make
      sudo make install
      
    6. Add extension to php.ini
      extension=apc.so
      
  8. Download and install MySQL-python 1.2.3c1
    sudo python setup.py install
    
  9. Download and install libjpeg.v7
    ./configure --enable-shared
    make
    sudo make install
    
  10. Download and install Python Imaging Library 1.1.6
    sudo python setup.py install
    

MySQL Startup Item for Mac OS X

Save the following as /Library/LaunchDaemons/org.mysql.mysqld.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>RunAtLoad</key>
	<true/>
	<key>Umask</key>
	<integer>7</integer>
	<key>UserName</key>
	<string>_mysql</string>
	<key>Disabled</key>
	<false/>
	<key>WorkingDirectory</key>
	<string>/usr/local/mysql</string>
	<key>GroupName</key>
	<string>_mysql</string>
	<key>KeepAlive</key>
	<true/>
	<key>Program</key>
	<string>/usr/local/mysql/bin/mysqld</string>
	<key>Label</key>
	<string>org.mysql.mysqld</string>
	<key>ProgramArguments</key>
	<array>
		<string>--user=_mysql</string>
	</array>
</dict>
</plist>

And in a bash session, run the following:

sudo chown root:wheel /Library/LaunchDaemons/org.mysql.mysqld.plist
sudo launchctl load /Library/LaunchDaemons/org.mysql.mysqld.plist
sudo launchctl start org.mysql.mysqld

Nginx Startup Script for Mac OS X

If you don't use MacPorts, and have a hard time finding a startup plist file for Nginx, and had trouble getting Nginx to startup with your custom plist file, this might be your solution:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>nginx</string>
    <key>Program</key>
    <string>/usr/local/nginx/sbin/nginx</string>
    <key>KeepAlive</key>
    <true/>
    <key>NetworkState</key>
    <true/>
    <key>LaunchOnlyOnce</key>
    <true/>
</dict>
</plist>

Just save this as /Library/LaunchDaemons/org.nginx.nginx.plist and perform the following in a bash session:

sudo chown root:wheel /Library/LaunchDaemons/org.nginx.nginx.plist
sudo launchctl load /Library/LaunchDaemons/org.nginx.nginx.plist
sudo launchctl start org.nginx.nginx