Log in

View Full Version : BeHappy+ AviSynth+ audio transcoding


tebasuna51
29th March 2025, 14:47
BeHappy+ AviSynth+ audio transcoding

After 20 years I open a new thread related to the old BeHappy (https://forum.doom9.org/showthread.php?t=104686).
Thanks to Kurt.noise we have a new version (https://github.com/Kurtnoise-zeus/BeHappy/releases/tag/3.4.0) to manage the ChannelMask property provided by AviSynth+ 3.7.3
If you don't want use AviSynth+ 3.7.3 (or nexts versions) please remain with the old BeHappy an stop read here.

If you have a Windows 64 bits, .NET Framework and AviSynth+ (now 3.7.4 (https://github.com/AviSynth/AviSynthPlus/releases/tag/v3.7.4)) installed you can try BeHappy+

BeHappy is a portable tool then I recommend create a folder like C:\Portable\BeHappy+ and unzip the attached file in that folder to obtain that structure:

C:\Portable\BeHappy+
<DIR> extensions
<DIR> plugins64
<DIR> encoder
116.736 AvisynthWrapper.dll
212.992 BeHappy.exe

Now the folders are empty (because the attach size limit) and need also unzip the extensions.7z attached.
You can create a desktop link to BeHappy.exe and execute it to obtain the figure attached, where:

1) You can Add or Clear and Drag & Drop any source file, and select+configure the decoder.

2) Tweak with any option. Like new option you can select the folder encoder instead the default.
Also you can force the channelmask if desired.

3) Select, configure and reorder some DSP AviSynth functions to manage the audio.

4) Select and configure the encoder and the output audio name.
Now is greyed with the encoder folder empty. Locate ffmpeg in your system to make a first test.
The dts sample L,R,Ls,Rs is converted to ac3 with the same channel layout.

I reserve next post to explain some questions:

tebasuna51
29th March 2025, 14:49
AVISYNTH DECODERS

AviSynth have internal decoders/load methods like AviSynth Import (*.avs), Wavsource and DirectShowSource but aren't recommended because can't export the ChannelMask.
With these methods you must set the Tweak ChMask or let the defaults for each num of channels.

The recommended method is use the new plugins decoders like:

LSMASHSource.dll
ffms2.dll
BestSource.dll

The 3 work fine sending the ChannelMask, and can be configured to apply DRC (recommended to 0) and select the stream index (if source is a container). By default -1 (first audio).

The old NicAudio.dll can't manage ChannelMask and is not recommended now, use it only for test.
I not found BassAudio.dll decoder 64 bits then can't be used here.

BeHappy use files s_*.ext in extensions folder to control how these decoders (s_ource) are configured and used.
Can be edited to change some parameters.

AVISYNTH FILTERS

To do some Digital Signal Processing AviSynth can use internal functions but also needs some plugins.

BeHappy can use files d_*.ext in extensions folder to define the process and users can modify or create new ones, but the defined now need some extra plugins like:

Shibatch.dll
soxfilter.dll
TimeStretch.dll

To install, update and verify the integrity of AviSynth I recommend use the Groucho tools like explain in this post and previous (https://forum.doom9.org/showthread.php?p=2017058#post2017058)

ENCODERS

Many modern command line encoders can be used because accept 'pipe' input and WAVE_FORMAT_EXTENSIBLE wav headers (also w64 and rf64) with the ChannelMask info.
But not all of them can translate the input channel layout to the output files, it is not a BeHappy problem, all ac3 channels layouts can't be translated to aac, only flac can do so.

Only the MusePack encoder (mpcenc.exe) not accept WAVE_FORMAT_EXTENSIBLE header and can't be used with BeHappy+, use old BeHappy if you need it.
The supported by the moment can be found in the links here (https://forum.doom9.org/showthread.php?t=185516)

You can use the subfolder 'encoder' or define a new one and select it in the Tweak option to put the downloaded encoders.
I use C:\Portable\0 shared with Foobar2000 and UsEac3to. Or you can use C:\Portable\BeHappy+\encoder with Foobar2000 and UsEac3to.
Also you can add C:\Portable\BeHappy+\encoder in your system %PATH% and use the encoders from any folder on your system.

BeHappy can use files e_*.ext in extensions folder to define how can be configured the encoders.
Like other *.ext files can be edited by the users.

HOW WORK WITHOUT AVISYNTH INSTALLED

Still without test it by me.

You need AviSynth.dll (and devil.dll with some unofficial versions) in the same folder than BeHappy.exe and all mentioned plugins in the subfolder 'plugins64'

32 BITS VERSION

It is usseless run BeHappy+ with AviSnth 2.6.0, but you can try 3.7.4 32 bits I'm not sure for what.
You can use the AudioLimiter.dll instead Soxfilter or the new AudioBoost.
And the BassAudio decoder.
Of course if you have a old PC without 64 bits but I can't test it.
Feel free to coment something about this.

tebasuna51
4th April 2025, 17:48
About the downmix 7.1 -> 5.1 methods.

I make a test over a Jurassic Park audio track fragment, with the maximum problem.
When mix the back and side channels with float samples

sur = MixAudio(blr, slr, 1.0, 1.0)

I obtain values until 2.0 than must be limited to 1.0 before encode, I can use:

AudioLimiter.dll (only 32 bits) with the function SoftClipperFromAudX(0.0)
Soxfilter.dll with SoxFilter("compand 0.0,0.0 -90,-84,-8,-2,-6,-1,-0,-0.1")
AudioBoost.dll with AudioBoost(boost=2.0,limit=0.98,curve=0,norm=false)

The first image show the output of 3 methods and volume values in low (0.2) and medium (0.5) range, and you can see how we obtain the same values than the float mix.
18923

Of course we can't obtain the same at peak values. In second image you can see how the high peaks (until 200%) are limited.
18924

For me the best method is the soxfilter, if somebody want test AudioBoost with other parameters feel free to comment here.

The soxfilter method (included in d_DownMix.ext can be used for 32 and 64 bits versions):
sur = MixAudio(blr, slr, 0.5, 0.5).SoxFilter("compand 0.0,0.0 -90,-84,-8,-2,-6,-1,-0,-0.1")
First mix the channels at 50% to remain with normalized samples and after aply a Gain of 2 for low volume and decrease the gain like can see in that curve 17534

In the full track (2h 6m) there are only 120382 samples (https://ffmpeg.org/ffmpeg-filters.html#toc-volumedetect) (<3 sec.) between -8 dB and -6 dB (Gain 2->1) and 25377 samples (<1 sec.) with less than -6 dB (Gain 1->0.5)
On another more normal track (Valerian... 2h 17m) there are 32335 samples (<1 sec.) between -8 dB and -6 dB and 3694 samples (<100 ms) with less than -6 dB.

Enjoying a second of each movie with higher surround volume is expensive (2 more speakers and more storage space)

tebasuna51
4th April 2025, 18:47
@Kurt.noise many thanks for your job. All my test work fine.

Not important, and only if you have time to do, two questions:

1) The encoder folder can be saved in BeHappy.state?

2) I never understand for what the output name is located before the encoder.
I think is more logic like that:

Kurt.noise
5th April 2025, 05:08
@Kurt.noise many thanks for your job. All my test work fine.
:goodpost:

1) The encoder folder can be saved in BeHappy.state?
Not yet. Might be implemented though.

2) I never understand for what the output name is located before the encoder.I think is more logic like that:
Yes, you're right. That can be switched as well.