Wednesday, October 3, 2012

How to open source!

I have heard a lot about open source stuff but haven't really been good enough "with computers" to attempt that. Until now! I am attempting to install an open-source video codec called x264 on my Mac.
  1. Have Xcode installed (got it from Apple; it's a standard installer).
  2. git comes pre-installed on my Mac.
  3. Go to a directory where you can put the source code. I just used the desktop; hopefully there won't be any permissions issues.
  4. Get the repository:
    git clone git://git.videolan.org/x264.git
  5. Go to the branch called "stable" (I don't know if this actually changed anything):
    git checkout stable
  6. Attempt to compile...Oh no! It needs an assembler:
    Found no assembler
    Minimum version is yasm-1.0.0
    If you really want to compile without asm, configure with --disable-asm.
    make: *** [config.mak] Error 1
  7. Get YASM:
    git clone git://github.com/yasm/yasm.git
  8. Compile it:
    ./configure
    make
    sudo make install
  9. Oh no! That didn't work...there isn't a configure file! There is a configure.ac file, though, which suggests maybe we need to generate it using autoconf:
    autoconf
  10. A error! Something about macros:
    configure.ac:14: error: possibly undefined macro: AM_INIT_AUTOMAKE
  11. Apparently there is this thing called aclocal:
    aclocal
    autoconf
  12. Still errors! According to the Internet, there should already be a configure file here. So I downloaded the tarball instead, and that has it. Okay. Let's try compiling it again:
    cd yasm-1.2.0
    ./configure
    make
    sudo make install
  13. That seems to have worked!
    $ which yasm
    /usr/local/bin/yasm
  14. Okay, now we can go back to the x264 folder and try installing it:
    cd ../x264
    ./configure
    make
    sudo make install
  15. It worked! Yay!
UPDATE: I subsequently needed to perform this installation on another computer, which I only have ssh access to at the moment. It turns out you can also install YASM using MacPorts, which is very easy:
sudo port install yasm

UPDATE 2: Later I needed to do this installation on a computer that didn't have ffmpeg installed, and also I'm not a super user for, so I had to install it to my home directory.
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-shared --prefix=/home/username/myBin
make
make install
and then re-install x264 with appropriate flags to tell it where the ffmpeg library is:
cd x264
export LDFLAGS="-L/home/username/myBin/lib"
export CFLAGS="-I/home/username/myBin/include"
export LD_RUN_PATH="/home/username/myBin/lib"
./configure --enable-shared --prefix=/home/username/myBin
make
make install
Then the call to x264 is:
x264 -q0 --preset placebo -o outputFile.mkv inputFile.avi