Showing posts with label qnap. Show all posts
Showing posts with label qnap. Show all posts

Friday, 5 April 2013

ffmpeg with libfaac support on QNAP TS-419P II NAS

Having recently upgraded to a QNAP TS-419P II NAS, I opted to replace the default ffmpeg installation with one that is compiled against libfaac for proper AAC encoding/decoding support.  On "normal" Linux distributions this is an easy task, and in all fairness it isn't particularly difficult on the QNAP either... but it did take me a couple of hours to sort the quirks out. And since I could only find a few random forum posts about the topic, I decided to create a simple step-by-step tutorial.

The TS-419P II has a 2 GHz Marvell Feroceon "Kirkwood" CPU, which is an armv5tel architecture, according to "uname -m" - we have to keep this in mind when compiling some of the packages, since we will be tuning builds for this architecture and will have to disable platform-specific assembly optimizations for the most part. Now, onto the steps involved:

  1. Install "Optware IPKG" via the QNAP Qpkg centre, if you haven't already.
  2. Log into the NAS via ssh.
  3. Install the some packages required for building ffmpeg and its dependencies via ipkg, by typing:
    ipkg update
    ipkg install gcc make pkgconfig libstdc++ git coreutils
    
  4. Ensure that /etc/ld.so.conf is set up so that /opt/lib is a location for shared libraries:
    if ! grep -q /opt/lib /etc/ld.so.conf; then echo /opt/lib >> /etc/ld.so.conf; else echo no; fi
    Alternatively, you can manually edit /etc/ld.so.conf and make sure it looks like this:
    /lib
    /usr/lib
    /usr/local/lib
    /opt/lib
    
  5. Install some codec libraries for ffmpeg via ipkg:
    ipkg install lame faad2 libogg libtheora libvorbis libmatroska libmpeg2
  6. Next, create a directory in which you can download and compile some required packages:
    mkdir /opt/build
  7. Build & install faac:
    cd /opt/build/
    wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
    tar -xzvf faac-1.28.tar.gz
    cd faac-1.28/
    CFLAGS="-march=armv5te -mtune=marvell-f -Wall -O2 -fstrength-reduce -finline-functions -ffast-math -fomit-frame-pointer" ./configure --prefix=/opt --enable-static=no
    make
    make install
    
  8. Build & install x264 (the version shipped by ipkg is too old for ffmpeg):
    cd /opt/build/
    git clone git://git.videolan.org/x264.git
    cd x264/
    CFLAGS="-march=armv5te -Wall -O2 -fstrength-reduce -finline-functions -ffast-math -fomit-frame-pointer" ./configure --prefix=/opt --enable-shared --system-libx264 --disable-asm
    make
    make install
    
  9. Build & install xvidcore:
    Note: the configure script for the latest xvidcore isn't compatible with the awk tool available on the QNAP NAS. The workaround is to download an earlier version of xvidcore as well and replace the current version's configure script with the older one; this is done in the example below:
    cd /opt/build/
    wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
    tar -xzvf xvidcore-1.3.2.tar.gz
    cd xvidcore/build/generic/
    wget http://downloads.xvid.org/downloads/xvidcore-1.3.0.tar.gz
    tar -xzvf vidcore-1.3.0.tar.gz
    cp -v xvidcore/build/generic/configure .
    CFLAGS="-march=armv5te -mtune=marvell-f -Wall -O2 -fstrength-reduce -finline-functions -ffast-math -fomit-frame-pointer" ./configure --prefix=/opt
    make
    make install
    
  10. Finally, build & install ffmpeg:
    cd /opt/build/
    wget http://ffmpeg.org/releases/ffmpeg-1.2.tar.gz
    tar -xzvf ffmpeg-1.2.tar.gz
    cd ffmpeg-1.2/
    CFLAGS="-march=armv5te -Wall -O2 -fstrength-reduce -finline-functions -ffast-math -fomit-frame-pointer" ./configure --prefix=/opt --enable-gpl --enable-nonfree --enable-bzlib --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --disable-asm --disable-debug
    make
    make install
    
  11. Run ldconfig to make sure all shared library additions are picked up:
    ldconfig
...and that's it. You now have a libfaac-enabled version of ffmpeg at /opt/bin/ffmpeg.

If you would like to override the system's ffmpeg with your new custom version, simply edit your PATH and make sure /opt/bin comes before /usr/bin.