aac+ encoder patch for ffmpeg

LATEST FFMPEG FROM GIT - IS ALREADY PATCHED! THIS HOWTO IS OBSOLETE!

 

HOWTO:

Follow steps below to patch FFMPEG that enables aac+ encoding.

You have to install libaacplus first!

 

Here is newer-patch for libaacplus2 code for debian/ubuntu linux:

$ svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg -r 25711
$ wget http://tipok.org.ua/downloads/media/aac+/libaacplus-simple-sample/ffmpeg-patch/ffmpeg-aacp2.10112010.diff
$ patch -p1 <
ffmpeg-aacp2.10112010.diff
$ ./configure --enable-libaacplus
$ make
# make install

 

 

 

Here is old-patch code for debian/ubuntu linux:

$ wget -O ffmpeg.tar.gz "http://git.ffmpeg.org/?p=ffmpeg;a=snapshot;h=124fefe867ef023a89ca4f4cc76e700342286b0d;sf=tgz"
$ tar -xvzf ffmpeg.tar.gz
$ cd ffmpeg
$
wget -O libswscale.tar.gz "http://git.ffmpeg.org/?p=libswscale;a=snapshot;h=1842e7d1cc122feea92dcd2d9a9a1adfb397aa24;sf=tgz"
$
tar -xvzf libswscale.tar.gz
$ wget http://tipok.org.ua/downloads/media/aac+/libaacplus-simple-sample/ffmpeg-patch/ffmpeg-aacp.7.diff
$ patch -p1 < ffmpeg-aacp.diff
$ ./configure --enable-libaacplus
$ make
# make install

 

CHANGELOG:

14.04.2009:

  • Stereo encoding bug fixed (encoded sound quality is much better)
  • Mono encoding implemented.
  • Audio specific config bits changed (now flash player can play aac+ "m4a" files, produced by ffmpeg)
  • Patch updated for latest FFmpeg

ENCODED SAMPLES:

sample32.aac
sample32.mp4
sample64.aac
sample64.mp4
source.mp2 (not aac+ encoded) - source file

 

Hello,

I loved your work on the aacplus reference encoder.. I also used the ffmpeg patch for the integration of it into ffmpeg so far so good :)

I just wanted to know if there is a way to enable it for 6ch encoding?

Best Regards,

Shai

diong (not verified)

Tue, 03/31/2009 - 17:55

i compiled it however i keep getting libaacplus not found.. i compiled libaacplus like teh read me said however still getting it so i then compiled libaacplus using this

./configure --prefix=/mingw --enable-static --disable-shared

still no go..

Danny (not verified)

Wed, 04/01/2009 - 12:12

Hi, I really appreciate your work on libaacplus. Thank you! However I still can't get the ffmpeg finding the libaacplus...
I have installed libiconv,gettext,glib and pkg-config. But keep getting this error during libaacplus autogen:

configure.ac:48: error: possibly undefined macro: AC_TYPE_INT16_T
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:49: error: possibly undefined macro: AC_TYPE_INT32_T
configure.ac:50: error: possibly undefined macro: AC_TYPE_INT8_T
configure.ac:51: error: possibly undefined macro: AC_TYPE_UINT16_T

Is it related to x86_64 environment?

Danny

> But keep getting this error during libaacplus autogen:
these macros were introduced in autoconf version 2.59-5 (or 2.59c). Install fresh autoconf (>= 2.59-5) to your system.
> Is it related to x86_64 environment?
No, it's related on autoconf version.

Dennis (not verified)

Fri, 07/17/2009 - 19:30

I get error compiling libaacplus.a statically into ffmpeg.

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-avfilter --enable-pthreads --enable-libamr-nb --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libx264 --enable-libxvid --disable-devices --enable-static --extra-libs=/usr/local/lib/libfaac.a --extra-libs=/usr/local/lib/libfaad.a --extra-libs=/usr/local/lib/libxvidcore.a --extra-libs=/usr/local/lib/libx264.a --extra-libs=/usr/local/lib/libamrnb.a --extra-libs=/usr/local/lib/libmp3lame.a --extra-libs=/usr/local/lib/liba52.a --extra-libs=/usr/local/lib/libaacplus.a --enable-libaacplus

"gcc -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I"/root/ffmpeg-0.5" -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -std=c99 -fomit-frame-pointer -pthread -I/usr/local/include/aacplus -g -Wdeclaration-after-statement -Wall -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wno-pointer-sign -Wcast-qual -Wwrite-strings -Wundef -O3 -fno-math-errno -c -o libavcodec/libaacplus.o libavcodec/libaacplus.c
libavcodec/libaacplus.c:28:22: error: put_bits.h: No such file or directory
libavcodec/libaacplus.c: In function Б─≤put_audio_specific_configБ─≥:
libavcodec/libaacplus.c:79: error: Б─≤PutBitContextБ─≥ undeclared (first use in this function)
libavcodec/libaacplus.c:79: error: (Each undeclared identifier is reported only once
libavcodec/libaacplus.c:79: error: for each function it appears in.)
libavcodec/libaacplus.c:79: error: expected Б─≤;Б─≥ before Б─≤pbБ─≥
libavcodec/libaacplus.c:80: warning: ISO C90 forbids mixed declarations and code
libavcodec/libaacplus.c:82: warning: implicit declaration of function Б─≤init_put_bitsБ─≥
libavcodec/libaacplus.c:82: error: Б─≤pbБ─≥ undeclared (first use in this function)
libavcodec/libaacplus.c:83: warning: implicit declaration of function Б─≤put_bitsБ─≥
libavcodec/libaacplus.c:90: warning: implicit declaration of function Б─≤flush_put_bitsБ─≥
make: *** [libavcodec/libaacplus.o] Error 1
"

Dennis (not verified)

Mon, 07/20/2009 - 18:48

./ffmpeg -i "01- String Quartet 11, Op.95 - I. Allegro con brio.wav" -acodec libaacplus -ab 128k AACPlus_128k.mp4
FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-avfilter --enable-pthreads --enable-libamr-nb --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libx264 --enable-libxvid --disable-devices --enable-static --extra-libs=/usr/local/lib/libfaac.a --extra-libs=/usr/local/lib/libfaad.a --extra-libs=/usr/local/lib/libxvidcore.a --extra-libs=/usr/local/lib/libx264.a --extra-libs=/usr/local/lib/libamrnb.a --extra-libs=/usr/local/lib/libmp3lame.a --extra-libs=/usr/local/lib/liba52.a --enable-libaacplus --extra-libs=/usr/local/lib/libaacplus.a
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Jul 17 2009 15:04:28, gcc: 4.2.4
Input #0, wav, from '01- String Quartet 11, Op.95 - I. Allegro con brio.wav':
Duration: 00:02:52.64, bitrate: 1411 kb/s
Stream #0.0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Output #0, mp4, to 'AACPlus_128k.mp4':
Stream #0.0: Audio: libfaac, 44100 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0.0 -> #0.0
[libaacplus @ 0x90523c0]No valid AAC+ SBR configuration found: br=128000, nChAAC=2, srAAC=22050
Error while opening codec for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

video encoding (not verified)

Sat, 07/25/2009 - 20:12

Shai, there is a way enable it for 6ch encoding. it's pretty long so please write if you have managed to solve it and if you didn't - i'll help. Great post btw thanks.

bloomburg (not verified)

Sat, 04/10/2010 - 11:27

Hello tipok
I appreciate your work so much.
I followed your instruction all the way but I get Unknown codec 'libaacplus'

My ffmpeg is like this.
FFmpeg version 0.5.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/usr/local --disable-debug --enable-shared --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-pthreads --enable-x11grab --enable-libx264 --enable-libxvid --enable-libvorbis --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libaacplus
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 1 / 52.59. 0
libavformat 52.31. 0 / 52.56. 0
libavdevice 52. 1. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0.10. 0
libpostproc 51. 2. 0 / 51. 2. 0
built on Apr 9 2010 19:59:08, gcc: 4.1.2 20080704 (Red Hat 4.1.2-46)
At least one output file must be specified

I need your advice.
Thanks,

hi tipok,

i'v got this error..any idea?

can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: configure
|===================================================================
|--- configure (revision 23548)
|+++ configure (working copy)
--------------------------
File to patch:

There is something broken with bitbuffer.c when running on 64 bit machine.
I fixed it so it runs without problems now.
Here is a patch, maybe you can add it.
Furthermore there is static data in the library, when running multiple instances from a single process data corruption happens. (when running mono and stereo stream at same time)
I have not fixed this yet, maybe someone else can take a look too.

oetelaar@oet-desktop:~/workspace/libaacplus-1.0.5$ hg diff bitbuffer.c
diff -r 76e88321842b bitbuffer.c
--- a/bitbuffer.c Sun Oct 03 19:19:43 2010 +0200
+++ b/bitbuffer.c Sun Oct 03 20:24:48 2010 +0200
@@ -194,7 +194,7 @@

COUNT_sub_start("ReadBits");

- /* return value is of type unsigned int, it can hold up to 32 bits
+ /* return value is of type unsigned int, it can hold up to 32 bits OETELAAR TODO wat is dit een 64 platform is??
this optimized code can read upto 25 Bits a time*/
ADD(1); BRANCH(1);
if (noBitsToRead >= 25) {
@@ -238,7 +238,7 @@
}

ADD(3); SHIFT(2);
- returnValue = returnValue << (31 - noBitsToRead - hBitBuf->rBitPos) >> (32 - noBitsToRead);
+ returnValue = returnValue << ((LongSize-1) - noBitsToRead - hBitBuf->rBitPos) >> (LongSize - noBitsToRead);

COUNT_sub_end();
return (returnValue);
@@ -284,7 +284,7 @@
bitsToWrite = min(hBitBuf->wBitPos + 1, noBitsToWrite);

ADD(4); SHIFT(3);
- tmp = (unsigned char) ( writeValue << (32 - noBitsToWrite) >> (32 - bitsToWrite) << (hBitBuf->wBitPos + 1 - bitsToWrite) );
+ tmp = (unsigned char) ( writeValue << (LongSize - noBitsToWrite) >> (LongSize - bitsToWrite) << (hBitBuf->wBitPos + 1 - bitsToWrite) );

ADD(1); SHIFT(2); LOGIC(1); /* (hBitBuf->wBitPos + 1 - bitsToWrite) --> already calculated */
msk = ~(((1 << bitsToWrite) - 1) << (hBitBuf->wBitPos + 1 - bitsToWrite));

Shai (not verified)

Thu, 11/25/2010 - 08:23

Hello there,

When encoding using libaacplus; Quicktime, iPhone, iPod etc... doesn't recognize the audio stream.
When playing using VLC or any other ffmpeg based player, it works fine. But with Quicktime I get no audio stream.

Does anybody have any idea why this is happening?

Best regards,

Shai

 Did You tried latest patch for ffmpeg? Seems this is problem in aac encoder config (extradata), If Yo can, just skip all extradata except first 2 bytes, but most decoders can't detect aac+ data without that additional info, and only aac data would be decoded. Need more research.

Yes I tried it via the ffmpeg new patch, and via the aacplusenc CLI.
Both produced unreadable audio streams in Quicktime.

BTW on ver 1.1.0 it works fine, and the audio streams are Quicktime, iDevices valid.

I will do some research of my own and exchange notes once I finished.

Thanks a lot :)

Shai

Soroush (not verified)

Sun, 01/30/2011 - 21:06

Hi tipok,
Thanks for the time and effort you put in libaacplus.

I applied installed libaacplus and patched ffmpeg successfully but when trigger 'make' on ffmpeg I get this error:

/home/xpro/ffmpeg/libavcodec/libavcodec.a(allcodecs.o): In function `avcodec_register_all':
/home/xpro/ffmpeg/libavcodec/allcodecs.c:356: undefined reference to `ff_libaacplus_encoder'
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1

Any idea how can I fix this?

Hello there,

In order to fix this, edit /libavcodec/libaacplus.c
And in the bottom of the page you'll see the following line: AVCodec libaacplus_encoder = { ...
Change it to this: AVCodec ff_libaacplus_encoder = {

And that's it :)

Best regards,

Shai

mmm must be typo as previous is quite the opposite, thanks for the find though

to recap
...
And in the bottom of the page you'll see the following line: AVCodec ff_libaacplus_encoder = { ...
Change it to this: AVCodec libaacplus_encoder = {

Anonymous (not verified)

Thu, 09/22/2011 - 15:16

Helllo is aac++ INPUT_FLOAT mode compatible with jackds floats?
I get a slight artifact is this mode broken any ideas..

Anonymous (not verified)

Thu, 09/22/2011 - 15:29

is libaacPlus broken for INPUT_FLOAT... does the encoder make any assumptions about the input in this mode... should jackd floats be compatible... I get a little artifact in the encoded data.. I cant force FAAD to decode in 32bit but I tested like so..

$ mplayer -really-quiet -vo null -vc dummy -af resample=96000 -ao pcm:nowaveheader:file=/dev/stdout http://192.168.1.77:9096/aacp64.aac 2>/dev/null | jack-stdin -b32 system:playback_1 system:playback_2

I checked with bit meter nice 32bit samples..

I checked the input with bitmeter all good 32bit every things green / healthy.

but the artifact persists
PLEASE HELP!!!

Anonymous (not verified)

Sat, 12/24/2011 - 21:18

ffmpeg fails to build when libaacplus and libvo_aacenc are enabled at configure, but ffmpeg will build fine if one of the two is not in configure line
is this a bug in ffmpeg ?
here is the error output
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libaacplus.a(bitbuffer.o): In function `CreateBitBuffer':
/home/s/BuildFolder/buildFFmpeg/buildexternal_libs/libaacplus-2.0.2/src/bitbuffer.c:54: multiple definition of `_CreateBitBuffer'
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libvo-aacenc.a(bitbuffer.o):(.text+0x0): first defined here
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libaacplus.a(bitbuffer.o): In function `DeleteBitBuffer':
/home/s/BuildFolder/buildFFmpeg/buildexternal_libs/libaacplus-2.0.2/src/bitbuffer.c:90: multiple definition of `_DeleteBitBuffer'
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libvo-aacenc.a(bitbuffer.o):(.text+0x40): first defined here
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libaacplus.a(bitbuffer.o): In function `ResetBitBuf':
/home/s/BuildFolder/buildFFmpeg/buildexternal_libs/libaacplus-2.0.2/src/bitbuffer.c:108: multiple definition of `_ResetBitBuf'
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libvo-aacenc.a(bitbuffer.o):(.text+0x60): first defined here
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libaacplus.a(bitbuffer.o): In function `CopyBitBuf':
/home/s/BuildFolder/buildFFmpeg/buildexternal_libs/libaacplus-2.0.2/src/bitbuffer.c:137: multiple definition of `_CopyBitBuf'
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libvo-aacenc.a(bitbuffer.o):(.text+0x90): first defined here
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libaacplus.a(bitbuffer.o): In function `GetBitsAvail':
/home/s/BuildFolder/buildFFmpeg/buildexternal_libs/libaacplus-2.0.2/src/bitbuffer.c:178: multiple definition of `_GetBitsAvail'
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libvo-aacenc.a(bitbuffer.o):(.text+0xc0): first defined here
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libaacplus.a(bitbuffer.o): In function `WriteBits':
/home/s/BuildFolder/buildFFmpeg/buildexternal_libs/libaacplus-2.0.2/src/bitbuffer.c:255: multiple definition of `_WriteBits'
/home/s/BuildFolder/buildFFmpeg/external_libs/lib/libvo-aacenc.a(bitbuffer.o):(.text+0xd0): first defined here
collect2: ld returned 1 exit status
make: *** [ffmpeg_g.exe] Error 1

Thanks for report. Seems, that we have problem with re-using same function names, again (this problem was with faac encoder too). I will try to fix it with renaming bitbuffer functions. Also as partial fix: try to use packaged version of libaacplus (for example from debian-multimedia repo, because we have libaacplus.sym file with only 6 exported functions, this may helps.