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 -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 -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

 

ffmpeg fails to build when

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,

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.

Where to get support for

Where to get support for AACPLUSLIB ???

is libaacPlus broken for

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!!!

Helllo is aac++ INPUT_FLOAT

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

Hi tipok, Thanks for the time

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

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

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 = {

Hello there, When encoding

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

 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

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

Can You set extradata size to

Can You set extradata size to 2 bytes only (in ffmpeg patch)?

There is something broken

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));

Thanks for patch, I added it

Thanks for patch, I added it to library. Also static vars will not enabled by default.

hi tipok, i'v got this

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:

I get this too. Any

I get this too. Any solutions?

Try using -p0 instead of -p1

Try using -p0 instead of -p1

Hello tipok I appreciate your

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,

I also loved your work. but I

I also loved your work. but I am also getting Unknown encoder 'libaacplus'.
Any solution for this?

Shai, there is a way enable

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.

Thanks a lot:) where should I

Thanks a lot:) where should I write you?

Shai

./ffmpeg -i "01- String

./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

3GPP implementation does not

3GPP implementation does not support bitrates over 64 kbps.

Hey, how can I switch SBR,

Hey,

how can I switch SBR, V2, V1? Is there pass1 and pass2?

Thanks.

it depends on selected

it depends on selected bitrate.
If less and include 44Kbps - then SBR v2 used.
In other cases - SBR v1.

It seems aacplus doesn't want

It seems aacplus doesn't want to go over 64kbps... Any way to force it?

Thanks.

3GPP implementation does not

3GPP implementation does not support bitrates over 64 kbps. If you want to encode with bitrate over 64kbps, it's better to use faac encoder.Here is image, that describes quality of he-aac he-aacv2 and aac-lc codecs depends on bitrate:
3GPP_mushra_18_48kbps_2.gif

I get error compiling

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
"

put_bits.h moved in newer

put_bits.h moved in newer ffmpeg version

ffmpeg-aacp.diif line 108 -

ffmpeg-aacp.diif
line 108
- +#include "put_bits.h"
+ +#include "bitsream.h"

it seems to compile ok now with FFMPEG 0.5.0

Thanks Tipok!

Same error but unable to fix

Same error but unable to fix with this bitsTream.h

With latest FFMPEG

With latest FFMPEG (git):
Hunk #1 FAILED at 376.
1 out of 1 hunk FAILED -- saving rejects to file libavcodec/Makefile.rej

You have to edit patch for

You have to edit patch for your ffmpeg version

Hi, The aac/mp4 files being

Hi,

The aac/mp4 files being produced can't be played in flash.
Do you have any idea on how to solve this?

Best Regards,

Shai

Yes, i tested various

Yes, i tested various variants of audio specific config bits, and i see that all 3 last bits have to be zero, then flash player can play it. So I fixed if at this patch. Here is my working test file. I installet this file url in JW-flv player wizard
 
P.S. Just redownload patch, I fixed it now.

Hi Danny, Please send me to

Hi Danny,

Please send me to shai@digital-blonde.com your gcc version bash version and make version..
I got it to work with mingw platform I will send you my notes regarding this.

Best Regards,

Shai

Hi, I really appreciate your

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

> 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.

Hi, You got to install

Hi,

You got to install libiconv,gettext,glib and pkg-config and then compile libaacplus and then ffmpeg will find it.

Best Regards,

Shai

i compiled it however i keep

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..

Hello, I loved your work on

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

This library based on 3gp

This library based on 3gp implementation, that can encode only 1 or 2 channels. So there's no way to encode 6ch.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
All comments are PRE-MODERATED! Enter what you see:
Image CAPTCHA
Enter the characters shown in the image.