Author Topic: BASSenc_AAC (AAC encoding)  (Read 7001 times)

Ian @ un4seen

  • Administrator
  • Posts: 24423
BASSenc_AAC (AAC encoding)
« on: 9 Aug '19 - 16:06 »
Here's a little AAC encoding add-on based on the FDK AAC encoder:

   www.un4seen.com/stuff/bassenc_aac.zip
   www.un4seen.com/stuff/bassenc_aac-linux.zip
   www.un4seen.com/stuff/bassenc_aac-linux-arm.zip
   www.un4seen.com/stuff/bassenc_aac-android.zip

No documentation yet, but the API is the same as the other encoding add-ons, with these "options" settings available:

  --object-type <value> ... "value" can be: 2/5/23/29/39. See here for descriptions: www.wikipedia.org/wiki/MPEG-4_Part_3#MPEG-4_Audio_Object_Types
  --vbr <value> ... "value" can be 0 (CBR) or 1-5 (VBR levels).
  --bitrate <value> ... bitrate (bps) for CBR.

The default is type 2 CBR with the bitrate based on the sample rate and channel count. No tagging or MP4 options currently, so it'll probably be mostly useful for streaming purposes (eg. with BASS_Encode_CastInit and BASS_Encode_ServerInit) rather than file writing.

AAC is patented and a licence is required to use it in commercial products. A licence can be obtained from Via:

   www.via-corp.com/us/en/licensing/aac/overview.html
« Last Edit: 21 Aug '19 - 14:20 by Ian @ un4seen »

Ian @ un4seen

  • Administrator
  • Posts: 24423
Re: BASSenc_AAC (AAC encoding)
« Reply #1 on: 21 Aug '19 - 14:22 »
An Android version has now been added in the 1st post.

kremk

  • Posts: 4
Re: BASSenc_AAC (AAC encoding)
« Reply #2 on: 28 Mar '20 - 14:22 »
Thank you for the add-on, it works very well with object-type 2 and 5 but when I try 29 for Parametric Stereo it returns BASS_ERROR_UNKNOWN on BASS_Encode_AAC_Start. Do I need to set some flags or something before starting? I've tried 24 to 128 bitrates with BASSEncode.BASS_ENCODE_PAUSE flag only.

Ian @ un4seen

  • Administrator
  • Posts: 24423
Re: BASSenc_AAC (AAC encoding)
« Reply #3 on: 30 Mar '20 - 17:54 »
Is the source stream stereo? BASS_Encode_AAC_Start currently gives a BASS_ERROR_UNKNOWN error if not. An extra check has been added for the next update so that it gives a more helpful BASS_ERROR_FORMAT error then instead.

kremk

  • Posts: 4
Re: BASSenc_AAC (AAC encoding)
« Reply #4 on: 31 Mar '20 - 13:56 »
Thank you, stereo was the issue as you said, now it's working well. I just forgot to switch back to stereo after testing speaker flags :)

scarboni

  • Posts: 53
Re: BASSenc_AAC (AAC encoding)
« Reply #5 on: 18 Feb '21 - 14:09 »
Hello ! I see that there is no library file for macos, but, it is also written that " The AAC/MP4 format is supported as standard by BASS via the OS's codecs on macOS and iOS", what does that mean exactly if we want to encode using AAC ?

Thank you !

Ian @ un4seen

  • Administrator
  • Posts: 24423
Re: BASSenc_AAC (AAC encoding)
« Reply #6 on: 18 Feb '21 - 16:05 »
The BASSenc_AAC add-on isn't currently available for macOS/iOS because they provide AAC encoding support as standard, which can be accessed via BASSenc's BASS_Encode_StartCA and BASS_Encode_StartCAFile functions. Please see the BASSenc documentation for details. You can also check the CONVERT.C example that's included in the BASSenc package for a little demonstration.

lordbarba

  • Posts: 11
Re: BASSenc_AAC (AAC encoding)
« Reply #7 on: 19 May '21 - 14:14 »
Does it work as AAC+ encoder on arm architecture?

Ian @ un4seen

  • Administrator
  • Posts: 24423
Re: BASSenc_AAC (AAC encoding)
« Reply #8 on: 19 May '21 - 15:54 »
Yes, it should do. You would put "--object-type 5" in the options for HE-AAC.

mhuellwegen

  • Posts: 2
Re: BASSenc_AAC (AAC encoding)
« Reply #9 on: 6 Mar '22 - 16:15 »
Many thanks for the great BASSenc_ACC add-on.

I just start using

   BASS_Encode_AAC_Start(stream1, "--object-type 2 --vbr 0 --bitrate 96000", 0, SELF_Encode_AAC_Proc, &self);

to join encoded Data in my own callback function

   CALLBACK SELF_Encode_AAC_Proc(HENCODE handle, DWORD channel, const void* buffer, DWORD length, QWORD offset, void* user) {

      ... some code here ...

   }



to generate an stereo.m3u8 playlist and in this context also the stereo-00001.ts, stereo-00002.ts, ... files on the fly for HLS streaming this via IIS Webserver.



Currently I managed to successfully interpret the ADTS header (the first 7 Bytes of the buffer on each CALLBACK call).

But I failed at the point joining multiple CALLBACK calls to e.g. ~4 seconds of 48000 samples @ 96000 bits/s stereo audio, calculate the exact audio length in seconds so i can save/deliver the ready to go .m3u8 and .ts file on the fly.
The main problem is that i do not know how many CALLBACK calls buffer to join to get ~4 seconds audio and then get te exact seconds (with e.g. 6 decimal places) since i have to declarate the exact duration time in the .m3u8 file.

Sample .m3u8 file:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5      or 4??
#EXTINF:4.010667,
stereo-00000.ts
#EXTINF:3.989333,
stereo-00001.ts
#EXTINF:4.010667,
stereo-00002.ts
#EXTINF:3.989333,
stereo-00003.ts




Can anyone give me any hints on how to do this?

Thanx in advance,
Martin


Ian @ un4seen

  • Administrator
  • Posts: 24423
Re: BASSenc_AAC (AAC encoding)
« Reply #10 on: 8 Mar '22 - 17:55 »
Each ADTS frame contains 1024 samples, so if you count the number frames received in your callback function then you can calculate the duration (multiply by 1024 and divide by the sample rate).

You can get the size of an ADTS frame (eg. to reach the next frame) like this:

Code: [Select]
size = ((head[3] & 0x3) << 11) | (head[4] << 3) | (head[5] >> 5);

Where "head" is a byte pointer to the ADTS header.

mhuellwegen

  • Posts: 2
Re: BASSenc_AAC (AAC encoding)
« Reply #11 on: 8 Mar '22 - 18:48 »
@Ian,

thanx a lot for your important hint.

Since i realized that it does not depend on the CALLBACKs buffer length parameter,
but on the 1024 samples divide by 48000/s in my case and multiplied with my targeted duration of about 4 sec as you mensioned,
i also realized that i will get an odd block count of 187,5 for exact 4 secs as well which means i will first join 187 blocks (3,989333333 exact seconds) and then 188 blocks (4,0106666 exact seconds)
and will get two ts-segments of totaly 375 blocks representing 8,0000 exact seconds of audio, if i am correct now.

This is what i've also noticed in lots of .m3u8 files as well, that odd and even segments have 3,989333 and 4,010666 seconds in that context.

I will try this soon and if someone is interested in i will report next time, how i managed to create a bunch of memory mapped files,
one for the playlist.m3u8 and the others as segment-0001.ts, -0002.ts, -0003.ts files and how i picked them up
by an IIS hosted default.aspx (.NET) page to deliver playlist and ts-segments on the fly.