Tuesday, May 6, 2014

FFmpeg with h264, AAC and VP8/VP9 support

Credits for the FFmpeg patch go to PC LOAD LETTER blog.

Please excuse the quite inconsistent use of env and export, I will clean this up when I find the time.

Currently this set includes the following libraries:
  • libx264(h264)
  • libmp3lame  (MP3)
  • libfaac (AAC)
  • libvpx (VP8/VP9)

Including
  • libfreetype
  • fontconfig
is only necessary if you want to embed captions or watermarks in your video files. If you do not need it, remove the corresponding lines in the FFmpeg configuration below.

Eventually you also have to add the zlib library.

After configuring each library, compile it with make and then call make install to install it.
The prefix parameter causes the libraries to be placed in lib under /usr/local/powerpc-none-linux-gnuspe as proposed by the Synology toolchain.

zlib

Download it from here and configure it:
CC=powerpc-none-linux-gnuspe-gcc \
./configure --prefix=/usr/local/powerpc-none-linux-gnuspe

libx264

Retrieve the libx264 code via GIT:
 git clone git://git.videolan.org/x264.git libx264

The configuration can be invoked via
env \
CC=/usr/local/powerpc-none-linux-gnuspe/bin/powerpc-none-linux-gnuspe-gcc \
LD=/usr/local/powerpc-none-linux-gnuspe/bin/powerpc-none-linux-gnuspe-ld \
RANLIB=/usr/local/powerpc-none-linux-gnuspe/bin/powerpc-none-linux-gnuspe-ranlib \
CFLAGS="-I/usr/local/powerpc-none-linux-gnuspe/include -mcpu=8548 \
 -mhard-float -mfloat-gprs=double" \
LDFLAGS="-L/usr/local/powerpc-none-linux-gnuspe/lib" && \
./configure \
 --prefix=/usr/local/powerpc-none-linux-gnuspe --cross-prefix=powerpc-none-linux-gnuspe- \
 --enable-shared --disable-asm --host=powerpc-none-linux-gnuspe \
 --disable-opencl \
 --disable-avs \
 --disable-ffms \
 --disable-gpac \
 --disable-lavf \
 --disable-swscale \
 --enable-pic \
 --enable-strip  

libmp3lame

Get the source code on Sourceforge and configure it:
./configure \
  --prefix=/usr/local/powerpc-none-linux-gnuspe \
  --host=powerpc-none-linux-gnuspe \
  --enable-shared \
  --disable-static \
  --disable-decoder

libfaac

Get the source code on www.audiocoding.com and configure it:
./configure --prefix=/usr/local/powerpc-none-linux-gnuspe/ \
   --host=powerpc-none-linux-gnuspe

libvpx

Fetch the source code:
 git clone https://chromium.googlesource.com/webm/libvpx libvpx
and configure it:
export LDFLAGS="-L/usr/local/powerpc-none-linux-gnuspe/lib"
export CROSS=powerpc-none-linux-gnuspe-
export CFLAGS="-I/usr/local/powerpc-none-linux-gnuspe/include -mcpu=8548 \
 -mhard-float -mfloat-gprs=double"
./configure \
 --prefix=/usr/local/powerpc-none-linux-gnuspe \
 --enable-shared \
 --target=ppc32-linux-gcc \
 --enable-vp8 \
 --enable-vp9 \
 --disable-examples \
 --disable-docs \
 --enable-postproc \
 --enable-vp9-postproc \
 --enable-pic \
 --disable-altivec \
 --disable-use_x86inc \
 --disable-unit_tests \
 --libc=/usr/local/powerpc-none-linux-gnuspe/powerpc-none-linux-gnuspe/libc/lib/

FFmpeg

Retrieve the FFmpeg source code via GIT:
  git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
The compilation of the FFMPEG source code to be run QorIQ/PPC systems requires a little patch.
--- ffmpeg/libavcodec/ppc/dsputil_ppc.c 2012-02-17 18:20:07.000000000 +0000
+++ ffmpeg-patched/libavcodec/ppc/dsputil_ppc.c 2012-10-18 22:15:50.740992688 +0100
@@ -116,7 +116,11 @@
  
     /* below the constraint "b" seems to mean "Address base register"
        in gcc-3.3 / RS/6000 speaks. seems to avoid using r0, so.... */
+    #if 1
+    __asm__ volatile("dcbz %0, %1" : : "r" (fakedata_middle), "r" (zero));
+    #else
     __asm__ volatile("dcbzl %0, %1" : : "b" (fakedata_middle), "r" (zero));
+    #endif
  
     for (i = 0; i < 1024 ; i ++) {
         if (fakedata[i] == (char)0)

A possible configuration for FFmpeg could be as follows.
Important is to disable of the Altivec code. When left enabled, the execution of the binaries fails with a segmentation fault.
Additionally I have disabled debugging, some audio/input/output filters, ffplay and ffserver that are not required in my case.

#
# FFMPEG configuration calling script
# 
env \
CFLAGS="-mcpu=8548 \
  -mhard-float \
  -mfloat-gprs=double" \
MARCH="-mcpu=8548 -mhard-float -mfloat-gprs=double" \
LDFLAGS="-L/usr/local/powerpc-none-linux-gnuspe/lib -L/usr/local/powerpc-none-linux-gnuspe/source/faac-1.28/libfaac/.libs" \
 && export PKG_CONFIG_PATH=/usr/local/powerpc-none-linux-gnuspe/lib/pkgconfig/ \
 && ./configure --prefix=/usr/local/powerpc-none-linux-gnuspe \
  --cross-prefix=/usr/local/powerpc-none-linux-gnuspe/bin/powerpc-none-linux-gnuspe- \
  --enable-cross-compile \
  --disable-yasm \
  --disable-altivec \
  --target-os=linux\
  --arch=ppc \
  --cpu=e500v2 \
  --enable-pic \
  --enable-pthreads \
  --disable-debug \
  --enable-libx264 \
  --enable-libmp3lame \
  --enable-libfaac \
  --disable-swscale-alpha \
  --disable-indev=alsa \
  --disable-indev=dv1394 \
  --disable-outdev=alsa \
  --disable-encoder=dca \
  --disable-encoder=ac3 \
  --disable-encoder=ac3_fixed \
  --disable-encoder=eac3 \
  --disable-decoder=dca \
  --disable-decoder=eac3 \
  --disable-decoder=truehd \
  --disable-iconv \
  --disable-podpages \
  --disable-ffplay \
  --disable-ffserver \
  --enable-gpl \
  --enable-version3 \
  --enable-nonfree --disable-doc \
  --extra-cflags='-I/usr/local/powerpc-none-linux-gnuspe/include' \
  --extra-ldflags='-L/usr/local/powerpc-none-linux-gnuspe/lib' \
  --enable-shared \
  --disable-static \
  --extra-version=ses \
  --enable-libfreetype \
  --pkg-config=pkg-config \
  --enable-fontconfig \
  --enable-optimizations \
  --enable-libvpx

No comments:

Post a Comment