Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Question about AC3 and DTS encoders (Read 44967 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Question about AC3 and DTS encoders

Some time ago, when making a DVD out of some footage, I came to realize that although we have some pretty great free solutions for DVD compliant stereo encoding (PCM WAV and MP2 via TooLAME) there isn't a widely adopted free solution for multichannel (AC3 or DTS) encoding. Why is that the case? Are AC3 and DTS inherently more complicated than, say, LAME or Vorbis? Maybe there's some sort of legal monkeywrench? Or is there just not enough interest in those formats?

Question about AC3 and DTS encoders

Reply #1
Some time ago, when making a DVD out of some footage, I came to realize that although we have some pretty great free solutions for DVD compliant stereo encoding (PCM WAV and MP2 via TooLAME) there isn't a widely adopted free solution for multichannel (AC3 or DTS) encoding. Why is that the case? Are AC3 and DTS inherently more complicated than, say, LAME or Vorbis? Maybe there are some sort of legal monkeywrench? Or is there just not enough interest in those formats?


There is a free LGPL AC3 encoder.  It is part of FFmpeg.  A while ago, I used the code from FFmpeg and added some additional features to create a standalone commandline encoder.  It isn't very well tested at the moment and probably will only work on Linux x86, which is the only platform I have tested it on.  I haven't tested multi-channel encoding either, but it should work in theory.

I have a website for it if anyone is interested.
http://jbr.homelinux.org/aften/
(note: this is on a new server, so if there are problems with the link just let me know and I'll move it)

AC3 is not really too complicated as compared to other audio codecs.  The specification is also very thorough and pretty easy to understand.  The only legal issue I know of has to do with Dolby's trademark of the AC3 name.

-Justin

Question about AC3 and DTS encoders

Reply #2
Oh, I know about ffmpeg's AC3 encoder, but all reports I read about it said it wasn't too good. Does your modification include other changes aside from the implementation of standalone encoding?

Question about AC3 and DTS encoders

Reply #3
There is a free LGPL AC3 encoder.  It is part of FFmpeg.  A while ago, I used the code from FFmpeg and added some additional features to create a standalone commandline encoder.  It isn't very well tested at the moment and probably will only work on Linux x86, which is the only platform I have tested it on.  I haven't tested multi-channel encoding either, but it should work in theory.


The FFMPEG encoder is very basic (following the F.Bellard tradition) , but might be a very valuable starting point. (and it's integer only, so it could be very interesting on some platforms)
In my opinion, it could be very interesting to create a cooperative project (like on sourceforge) around your command-line version.

I think that to attract potential developpers, you should have an interesting project and some basic tools. You already have the interesting project.
Regarding tools, some good basic ones would be:
*a command line interface (already done) to ease experimentation with the encoder
*a library structure could be a good "selling" point
*a way to conveniently analyse the encoding choices

Regarding this last point, some output regarding thresholds and bit allocation into a text file that could be further displayed using Gnuplot could do the trick. (it should be way faster than to write a graphical frontend in Gtk...)

With those points, your project could have a good starting. (although we never know)

Question about AC3 and DTS encoders

Reply #4
It would be great to see a project arise from this .

Question about AC3 and DTS encoders

Reply #5
(and it's integer only, so it could be very interesting on some platforms)


Quote from: http://jbr.homelinux.org/aften/ link=msg=0 date=
Converted the fixed-point algorithms to floating-point


But it might not be that difficult to revert back for those that are interested...

Question about AC3 and DTS encoders

Reply #6

There is a free LGPL AC3 encoder.  It is part of FFmpeg.  A while ago, I used the code from FFmpeg and added some additional features to create a standalone commandline encoder.  It isn't very well tested at the moment and probably will only work on Linux x86, which is the only platform I have tested it on.  I haven't tested multi-channel encoding either, but it should work in theory.


The FFMPEG encoder is very basic (following the F.Bellard tradition) , but might be a very valuable starting point. (and it's integer only, so it could be very interesting on some platforms)
In my opinion, it could be very interesting to create a cooperative project (like on sourceforge) around your command-line version.

You're right that the FFMpeg AC3 encoder is very simple.  I have added a few things, but there could be a lot more done (e.g. add channel coupling, better exponent strategy selection).

Quote
I think that to attract potential developpers, you should have an interesting project and some basic tools. You already have the interesting project.
Regarding tools, some good basic ones would be:
*a command line interface (already done) to ease experimentation with the encoder
*a library structure could be a good "selling" point
*a way to conveniently analyse the encoding choices

Regarding this last point, some output regarding thresholds and bit allocation into a text file that could be further displayed using Gnuplot could do the trick. (it should be way faster than to write a graphical frontend in Gtk...)

With those points, your project could have a good starting. (although we never know)

A library structure and a better build system are probably the next step.  The reason I converted to floating-point from fixed-point was because the stereo rematrixing was generating high-frequency noise with fixed-point due to the inaccuracy.  I could easily make it a compile-time option and leave out the stereo rematrixing in the fixed-point version.

I have done some experimenting with Gnuplot output, so that wouldn't be too difficult.

Thanks for the encouragement.
-Justin

Question about AC3 and DTS encoders

Reply #7
Main reason that there is no "free" DTS-encoder is that there is no spec
available afaik, unlike AC3, where something can be found in the ATSC docs
(bitstream syntax etc.).
Both companies are earning money via license fees/royalities, so they are for sure
not interested in supporting anything "free". Obviously, they can't do very much
against a de-/encoder written from scratch from a document open to the
public...

Question about AC3 and DTS encoders

Reply #8
Hi,
Thanks to some improvements posted on the doom9 forum, I have done some work on Aften today and released a new version.

http://jbr.homelinux.org/aften/aften-0.01.tar.bz2
  • simple configure script
  • piped input and output
  • corrected 6-channel mapping
  • corrected defaults for mix levels
  • commandline options
  • quiet mode (no console output)
  • per-frame or average statistics
  • big-endian support (not tested though)

Here is the output from "aften -h"
Code: [Select]
Aften: A/52 audio encoder
(c) 2006 Justin Ruggles

usage: aften [options] <input.wav> <output.ac3>
options:
       [-h]         Print out list of commandline options
       [-v #]       Verbosity (controls output to console)
                        0 = quiet mode
                        1 = show average stats (default)
                        2 = show each frame's stats
       [-b #]       CBR bitrate (default: none)
       [-q #]       VBR quality [1 - 1023] (default: 200)
       [-w #]       Bandwidth [0 - 60] (default: adaptive)
       [-m #]       Stereo rematrixing
                        0 = independent L+R channels
                        1 = mid/side rematrixing (default)
       [-s #]       Block switching
                        0 = use only 512-point MDCT (default)
                        1 = selectively use 256-point MDCT


-Justin


Question about AC3 and DTS encoders

Reply #10
I've compiled it under VC++ 8.
Only minor changes needed to make it compile (like there's seem to be no <inttypes.h> in MSC)

I've compressed some 44.1kHz/Stereo/16bit wav files.

Looks like Foobar2000 (0.8.3) doesn't like the output of Aften - it refuses to play the resultant file.

Media Player Classic (6.4.9.0) playes CBR correctly while it chokes on VBR (it tries to play it though).

I'm off to try other playback options...

Question about AC3 and DTS encoders

Reply #11
BeSweet had no problem decoding VBR.

I've successfully ABX-ed (12/12) the CBR 256kbit mode (-b 256000).
I think the agressive lowpass (~14 kHz) made it easy.

Does anyone know at what bitrates should a 2ch AC3 achieve transparency?
I've seen DVDs use 192kbit so I assume it should be somewhere in that ballpark.

Question about AC3 and DTS encoders

Reply #12
I don't think the time has yet come to ABX this new encoder. It might take a while until it's on par with commercial solutions.

Question about AC3 and DTS encoders

Reply #13

Hi,
Thanks to some improvements posted on the doom9 forum, I have done some work on Aften today and released a new version.

http://jbr.homelinux.org/aften/aften-0.01.tar.bz2


On your Aften page the current version is 0.02, and the links go to different files as well. So what package to download?


Sorry...I got overly ambitious and decided to add a few more commandline options, so I made a 0.02 version.  I didn't mean to confuse things.  From now on I'll keep the 0.02 version there and add another link for aften-current.tar.bz2 which will always reflect the newest development version.

-Justin

Question about AC3 and DTS encoders

Reply #14
I've compiled it under VC++ 8.
Only minor changes needed to make it compile (like there's seem to be no <inttypes.h> in MSC)

I've compressed some 44.1kHz/Stereo/16bit wav files.

Looks like Foobar2000 (0.8.3) doesn't like the output of Aften - it refuses to play the resultant file.

Media Player Classic (6.4.9.0) playes CBR correctly while it chokes on VBR (it tries to play it though).

I'm off to try other playback options...


Thank you for the great feedback!  I will add inttypes.h emulation soon.  As I am not running a Windows machine, I pretty much only have access to 1 decoder, liba52, which handles VBR just fine.  Your information is very interesting, as I can't find anywhere in the specification where it says all frames in a stream must be the same size.  I was worried more about hardware compatibility, but it seems there are indeed some software issues out there.  I think I will maybe add a big warning when trying to encode in VBR mode.  I am glad BeSweet gets it right.  Maybe it uses liba52 or some derivative of it?

As a response to the ABX-related post, maybe I should have warned that the quality pretty much sucks as compared to other modern codecs or even full-spec AC-3 implementations.  I'm more concerned with compatibility and adding specification features at this point.  There is a long way to go.  I don't have the best ears for quality right now, but I have noticed CBR starts getting noticeably worse below 192kbps.  With VBR it pushes it a little lower, maybe 160 or so.  But none of this is objective, so it doesn't matter much.  I do need to work on the cutoff frequency.  I was maybe a little too aggressive with lowering the bandwidth rather than letting the bitrate increase and/or SNR (the "quality" param) decrease.  I just need to do some objective tests to tweak the settings...or enable users to adjust them more! 

I am pretty new to audio encoding.  Lossless sure is much easier to test...  I need to look more into improving my listening skills and do some practice listening tests.  Any help will with testing will be very much appreciated!

Thanks!
-Justin

Question about AC3 and DTS encoders

Reply #15
Ok for the inttypes I made a new header file (I called it common.h):
Code: [Select]
#if defined(_WIN32) && defined(_MSC_VER)

typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;

#ifdef _WIN64
typedef __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else
typedef __int32 intptr_t;
typedef unsigned __int32 uintptr_t;
#endif

#define inline __inline

#define CONFIG_WIN32

#pragma warning(disable:4267 4244 4305)

#else

#include <inttypes.h>

#include "config.h"

#endif
I made sure I call this header early enough in each *.c file.

I also found a bug which caused the program to crash in release (optimized) mode.
In dsp.c in the function mdct512 the end loop should be
Code: [Select]
    for(i=0; i<256; i++) {
        out[i] = coef[i];
    }
instead of
Code: [Select]
    for(i=0; i<512; i++) {
        out[i] = coef[i];
    }

As for audio encoding I'm not experienced in it either - but that won't stop me


Question about AC3 and DTS encoders

Reply #17
I don't know much about these things, but I think I found what you're talking about. [link]


Actually not enough, since only the frame headers are described there...rest is considered
DTS confidential. Anyway, thanks for the link. :-)

Question about AC3 and DTS encoders

Reply #18
After reading AC3 sources I have to say - this is quite a strange format.
Unlike MP3, AAC, DTS and others Dolby tried to put the psy model in the decoder 

I think that computing power from MDCT is not correct, because a representation of a signal is phase dependent with MDCT. That's why psy models use FFT instead.

Unfortunately the quantatization of the individual critical bands cannot be coded - it's computed from the exponent values. The only idea that I have is boosting the exponents in the bands with power loss to force higher relative masking treshold - but I'm not sure if it can be done so it results in a coding gain.

The less trivial stuff is to adjust the following (hardcoded) values:
Code: [Select]
    frame->sdecaycod = 2;
    frame->fdecaycod = 1;
    frame->sgaincod = 1;
    frame->dbkneecod = 2;
    frame->floorcod = 4;
    frame->fgaincod = 4;


Btw, I used -b 192000 -w 38 and so it has a 16.1kHz cutoff which I like much better than the variable bandwidth setting. It's not without artifacts but it sounds promising so maybe some tweaking can help.
I've tried -s 1 (block switching) but it caused more artifacts so I think it needs some tuning before it can be useful.

Question about AC3 and DTS encoders

Reply #19
@Justin : what is the difference between aften & aften_g ?

Question about AC3 and DTS encoders

Reply #20
@Justin : what is the difference between aften & aften_g ?

"aften_g" is compiled with debugging symbols.  The "g" refers to the gcc option "-g".  This makes debugging easier (gdb will give the file, function, and line number of an error), but the binary is larger.  The "aften" binary is the same as "aften_g", but the debugging symbols are stripped so the file is smaller.

-Justin

Question about AC3 and DTS encoders

Reply #21
Justin Ruggles> I couldn't find a binary on your web page. Is it because of U.S. patent legislative? If it is a problem to provide a binary, I think you might ask rjamorim to host it at rarewares.org.

And one more question: Is it easy to integrate your changes back to FFMPEG? Many other projects use FFMPEG as a base for AC3 encoding. FFDShow or QuEnc for example. Or can these projects easily switch to Aften?

Anyway thank you for this encoder. Now I can encode from whatever format directly to AC3 in foobar2000 or BeHappy. I hope BeLight will be updated soon to support Aften. Are you working on it kurtnoise?

I'll be creating my own DVD next week and I'll use Aften for AC3 encoding (unfortunately only 2.0 stereo). I'll let you know some feedback then.

Question about AC3 and DTS encoders

Reply #22
Some binaries for win32 OS can be found here...


Concerning Aften with BeLight. Yes, I'll try asap.

Question about AC3 and DTS encoders

Reply #23
Justin Ruggles> I couldn't find a binary on your web page. Is it because of U.S. patent legislative? If it is a problem to provide a binary, I think you might ask rjamorim to host it at rarewares.org.

It's not because of patents.  I really haven't heard about specific patents related to AC3.  The specification hints that there might be some, but doesn't say who/what/where like other specifications do.  So unless I get some nasty letter from Dolby or someone else I am just going with what I've got.  AFAIK the only legal issues are trademarks owned by Dolby, but I do not claim Aften to be Dolby Digital or Dolby Surround compliant.  In fact, I might even put a warning in the README file that Aften is not a licensed Dolby product, and therefore any content created with Aften should not be labeled as "Dolby Digital" or "Dolby Surround".  I am probably already protected by the LGPL license from the actions of the program's users, but it couldn't hurt.

Back to the point, the reason for no binary is basically because I don't use Windows and haven't really had the time to setup a working Mingw cross-compiler/Wine testing environment.  If I get really brave (or really desparate) I might get a 2nd hard drive and start using Win2k again for testing purposes.  I guess I could provide Linux static binaries.  I might do that if Sourceforge approves the project to be hosted there.  It's a good thing kurtnoise is doing a fabulous job of releasing binaries about as quickly as I make changes.

Quote
And one more question: Is it easy to integrate your changes back to FFMPEG? Many other projects use FFMPEG as a base for AC3 encoding. FFDShow or QuEnc for example. Or can these projects easily switch to Aften?

Some things yes, some no.  They would probably accept the changes if I made it support either fixed-point or floating point.  Right now the main benefit of Aften over FFmpeg is in the fact that it is a standalone AC3 encoder, and that it supports VBR, variable bandwidth, and stereo rematrixing.  If I add enough good features I might be able to port the ones which will work in fixed-point mode back into FFmpeg.

Quote
[...]
I'll be creating my own DVD next week and I'll use Aften for AC3 encoding (unfortunately only 2.0 stereo). I'll let you know some feedback then.

Great!  Maybe I'll have DRC implemented by then...if I'm not too exhausted. I'm going through inventory at work this week. Today was the first day...12 hours of going up-and-down ladders counting stuff! I'm too tired to think.

-Justin

Question about AC3 and DTS encoders

Reply #24
Would it be a good idea to organize a listening test to compare aften to current commercial solutions?