Log in

View Full Version : AC3 DRC0 via Avisynth Script


-QfG-
20th June 2021, 22:13
Hi there,

has anybody an idea how i can erase the DRC from AC3 Files via Avisynth?

I know that i can remove DRC with FFMPEG, but i need help with this function via Avisynth. If i use an Avisynth script via FFMPEG, FFMPEG skips this line.

mp3dom
21st June 2021, 09:20
Since Avisynth doesn't touch the original source, your best bet is to use nicsource as ac3 decoder and set drc to zero. This will ignore that flag. If you can use something else, you can use eac3to which will set dialnorm to -31 (which means "don't do anything"). As far as I know, ffmpeg decoding of ac3 files is subpar, since the volume will be very different from the source, even if drc is set to zero. I don't know how this translates with source filters like lsmash or libav...

tebasuna51
22nd June 2021, 14:07
A wav source, encoded with DN = -25 dB, DRC = Film Standard, and after decoded with ffmpeg and some AviSynth decoders ():

AC3 decoded using drc : ffmpeg, FFAudioSource(), LWLibavAudioSource(), NicAc3Source(DRC=1), BestAudioSource()
AC3 decoded with drc 0: ffmpeg -drc_scale 0, NicAc3Source(), bassAudioSource()

wav source AC3 decoded using drc AC3 decoded with drc 0
------------------- --------------------- ----------------------
RMS power L: 16.30% (-15.76 dB) 5.99% (-24.45 dB) 16.10% (-15.86 dB)
RMS power R: 16.44% (-15.68 dB) 6.82% (-23.33 dB) 16.24% (-15.79 dB)
Min value L: -96.04% (-0.35 dB) -41.47% (-7.65 dB) -100.00% (0.00 dB)
Min value R: -95.96% (-0.36 dB) -40.95% (-7.75 dB) -97.32% (-0.24 dB)
Max value L: 94.69% (-0.47 dB) 43.56% (-7.22 dB) 97.69% (-0.20 dB)
Max value R: 94.52% (-0.49 dB) 41.85% (-7.57 dB) 98.64% (-0.12 dB)

Like you can see to preserve the full volume in AviSynth you need use NicAc3Source() or bassAudioSource()

The volume reduction is not only by Dialog Normalization (31-27= 6 dB) but also for Dynamic Range Compression (Film Standard here).
This AC3 have a Dyn. Range min/max : -11,78 / 1,02 dB

The DN can be changed in the ac3 stream, but not the DRC data.
To erase the DRC data you need recode the AC3 with ffmpeg (DRC data not created, select the same bitrate):

ffmpeg -drc_scale 0 -i "INPUT.ac3" -c:a ac3 -b:a 640k -center_mixlev 0.707 "OUTPUT.ac3"

[EDIT] Added Feature request for FFAudioSource() (https://github.com/FFMS/ffms2/issues/386)
Added Feature request for BestAudioSource() (https://github.com/vapoursynth/bestaudiosource/issues/4)
I don't know where add Feature request for LWLibavAudioSource() because https://forum.doom9.org/showthread.php?p=1943308#post1943308

tebasuna51
23rd June 2021, 14:30
Bump to see added info (BestAudioSource and feature requests)

-QfG-
24th June 2021, 20:01
So, i have found a solution for me, many thanks for the response and the idea with NICDTS Source.

I have downloaded the sourcecode from BeHappy and i have modified some things for me. Also i have integrated the newest Timestretch Plugin from Avisynth+ 3.7.0.

Now i can make DRC0 audio files from ac3 files, i'm searching for a container solution, too. But it's a step forward:

https://i.imgur.com/cou3njw.png

The Red one is the AC3 File without DRC!

https://i.imgur.com/Mrhpmta.png

GMJCZP
24th June 2021, 22:24
Very interesting all this, could the option to activate / deactivate DRC be formally included in BeHappy?

Edit: could activating DRC be done in compression mode given certain parameters? I have this doubt aside.

-QfG-
25th June 2021, 02:35
Edit s_NicAudio.ext with an editor and change this Inline:

...then choose for ac3 Input Files "NicAC3Source" and the Output File is DRC Free.

<?xml version="1.0"?>
<BeHappy.Extension xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://workspaces.gotdotnet.com/behappy">
<AudioSource UniqueID="1B1E7952-5316-4C88-88DF-24EDCCD8A8C7">
<Plugin>
<MultiOptionSource Type="BeHappy.Extensions.MultiOptionSource, BeHappy">
<DialogWidth>200</DialogWidth>
<TitleFormatString>{0}</TitleFormatString>
<LoadAvsPlugin>nicaudio.dll</LoadAvsPlugin>
<SupportedFileExtension>mpg</SupportedFileExtension>
<SupportedFileExtension>mpeg</SupportedFileExtension>
<SupportedFileExtension>mpa</SupportedFileExtension>
<SupportedFileExtension>mp3</SupportedFileExtension>
<SupportedFileExtension>mp2</SupportedFileExtension>
<Script>%options%</Script>
<Radiobutton Name="NicMPG123Source">
<Value>NicMPG123Source("{0}")</Value>
</Radiobutton>
<Radiobutton Name="NicMPG123Source (Normalize)">
<Value>NicMPG123Source("{0}", true)</Value>
</Radiobutton>
</MultiOptionSource>
</Plugin>
</AudioSource>
<AudioSource UniqueID="ff49a26c-7348-4674-a28f-17bf7fcb38cc">
<Plugin>
<MultiOptionSource Type="BeHappy.Extensions.MultiOptionSource, BeHappy">
<DialogWidth>200</DialogWidth>
<TitleFormatString>{0}</TitleFormatString>
<LoadAvsPlugin>nicaudio.dll</LoadAvsPlugin>
<SupportedFileExtension>ac3</SupportedFileExtension>
<Script>%options%</Script>
<Radiobutton Name="NicAc3Source">
<Value>NicAc3Source("{0}", DRC=0)</Value>
</Radiobutton>
<Radiobutton Name="NicAc3Source (DRC)">
<Value>NicAc3Source("{0}", DRC=1)</Value>
</Radiobutton>
</MultiOptionSource>
</Plugin>
</AudioSource>
<AudioSource UniqueID="bd3ac54a-5c6a-4f9f-9d42-2d3990a0fafd">
<Plugin>
<MultiOptionSource Type="BeHappy.Extensions.MultiOptionSource, BeHappy">
<DialogWidth>0</DialogWidth>
<TitleFormatString>{0}</TitleFormatString>
<LoadAvsPlugin>nicaudio.dll</LoadAvsPlugin>
<SupportedFileExtension>dts</SupportedFileExtension>
<Script>%options%</Script>
<Radiobutton Name="NicDtsSource">
<Value>NicDtsSource("{0}", DRC=0)</Value>
</Radiobutton>
<Radiobutton Name="NicDtsSource (DRC)">
<Value>NicDtsSource("{0}", DRC=1)</Value>
</Radiobutton>
</MultiOptionSource>
</Plugin>
</AudioSource>
<AudioSource UniqueID="e44ed4c0-e096-11dc-95ff-0800200c9a66">
<Plugin>
<MultiOptionSource Type="BeHappy.Extensions.MultiOptionSource, BeHappy">
<DialogWidth>250</DialogWidth>
<TitleFormatString>Nic{0}</TitleFormatString>
<LoadAvsPlugin>nicaudio.dll</LoadAvsPlugin>
<SupportedFileExtension>pcm</SupportedFileExtension>
<SupportedFileExtension>lpcm</SupportedFileExtension>
<Script>%options%</Script>
<Radiobutton Name="LPCM BluRay 48000Hz, 16int, 2ch">
<Value>NicLPCMSource("{0}", 48000, -16, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM BluRay 48000Hz, 24int, 2ch">
<Value>NicLPCMSource("{0}", 48000, -24, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM BluRay 48000Hz, 16int, 6ch">
<Value>NicLPCMSource("{0}", 48000, -16, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM BluRay 48000Hz, 24int, 6ch">
<Value>NicLPCMSource("{0}", 48000, -24, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM BluRay 48000Hz, 16int, 8ch">
<Value>NicLPCMSource("{0}", 48000, -16, 8)</Value>
</Radiobutton>
<Radiobutton Name="LPCM BluRay 48000Hz, 24int, 8ch">
<Value>NicLPCMSource("{0}", 48000, -24, 8)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 48000Hz, 16int, 2ch">
<Value>NicLPCMSource("{0}", 48000, 16, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 48000Hz, 20int, 2ch">
<Value>NicLPCMSource("{0}", 48000, 20, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 48000Hz, 24int, 2ch">
<Value>NicLPCMSource("{0}", 48000, 24, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 48000Hz, 16int, 6ch">
<Value>NicLPCMSource("{0}", 48000, 16, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 48000Hz, 20int, 6ch">
<Value>NicLPCMSource("{0}", 48000, 20, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 48000Hz, 24int, 6ch">
<Value>NicLPCMSource("{0}", 48000, 24, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 44100Hz, 16int, 2ch">
<Value>NicLPCMSource("{0}", 44100, 16, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 44100Hz, 20int, 2ch">
<Value>NicLPCMSource("{0}", 44100, 20, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 44100Hz, 24int, 2ch">
<Value>NicLPCMSource("{0}", 44100, 24, 2)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 44100Hz, 16int, 6ch">
<Value>NicLPCMSource("{0}", 44100, 16, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 44100Hz, 20int, 6ch">
<Value>NicLPCMSource("{0}", 44100, 20, 6)</Value>
</Radiobutton>
<Radiobutton Name="LPCM 44100Hz, 24int, 6ch">
<Value>NicLPCMSource("{0}", 44100, 24, 6)</Value>
</Radiobutton>
</MultiOptionSource>
</Plugin>
</AudioSource>
<AudioSource UniqueID="58ab9132-50c8-11dc-8314-0800200c9a66">
<Plugin>
<MultiOptionSource Type="BeHappy.Extensions.MultiOptionSource, BeHappy">
<DialogWidth>250</DialogWidth>
<TitleFormatString>Nic{0}</TitleFormatString>
<LoadAvsPlugin>nicaudio.dll</LoadAvsPlugin>
<SupportedFileExtension>raw</SupportedFileExtension>
<SupportedFileExtension>dat</SupportedFileExtension>
<SupportedFileExtension>wav</SupportedFileExtension>
<SupportedFileExtension>w64</SupportedFileExtension>
<SupportedFileExtension>aif</SupportedFileExtension>
<SupportedFileExtension>au</SupportedFileExtension>
<SupportedFileExtension>caf</SupportedFileExtension>
<SupportedFileExtension>bwf</SupportedFileExtension>
<Script>%options%</Script>
<Radiobutton Name="RaWav IgnoreLength always">
<Value>RaWavSource("{0}", 1)</Value>
</Radiobutton>
<Radiobutton Name="RaWav IgnoreLength if wav > 2GB">
<Value>RaWavSource("{0}", 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav IgnoreLength if wav > 4GB">
<Value>RaWavSource("{0}", 4)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 16int, 2ch">
<Value>RaWavSource("{0}", 48000, 16, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 24int, 2ch">
<Value>RaWavSource("{0}", 48000, 24, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 32int, 2ch">
<Value>RaWavSource("{0}", 48000, 32, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 32float, 2ch">
<Value>RaWavSource("{0}", 48000, 33, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 16int, 6ch">
<Value>RaWavSource("{0}", 48000, 16, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 24int, 6ch">
<Value>RaWavSource("{0}", 48000, 24, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 32int, 6ch">
<Value>RaWavSource("{0}", 48000, 32, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 48000Hz, 32float, 6ch">
<Value>RaWavSource("{0}", 48000, 33, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 16int, 2ch">
<Value>RaWavSource("{0}", 44100, 16, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 24int, 2ch">
<Value>RaWavSource("{0}", 44100, 24, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 32int, 2ch">
<Value>RaWavSource("{0}", 44100, 32, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 32float, 2ch">
<Value>RaWavSource("{0}", 44100, 33, 2)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 16int, 6ch">
<Value>RaWavSource("{0}", 44100, 16, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 24int, 6ch">
<Value>RaWavSource("{0}", 44100, 24, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 32int, 6ch">
<Value>RaWavSource("{0}", 44100, 32, 6)</Value>
</Radiobutton>
<Radiobutton Name="RaWav 44100Hz, 32float, 6ch">
<Value>RaWavSource("{0}", 44100, 33, 6)</Value>
</Radiobutton>
</MultiOptionSource>
</Plugin>
</AudioSource>
</BeHappy.Extension>

tebasuna51
25th June 2021, 10:43
Very interesting all this, could the option to activate / deactivate DRC be formally included in BeHappy?

BeHappy was make to transcode audio, not to play, then the default is don't apply the DRC, but pressing the Configure... button you can use some NicAudio options, see the attached image.

This is included formally in Behappy in s_NicAudio.ext:
...
<MultiOptionSource Type="BeHappy.Extensions.MultiOptionSource, BeHappy">
<DialogWidth>200</DialogWidth>
<TitleFormatString>{0}</TitleFormatString>
<LoadAvsPlugin>nicaudio.dll</LoadAvsPlugin>
<SupportedFileExtension>ac3</SupportedFileExtension>
<Script>%options%</Script>
<Radiobutton Name="NicAc3Source">
<Value>NicAc3Source("{0}")</Value>
</Radiobutton>
<Radiobutton Name="NicAc3Source (DRC)">
<Value>NicAc3Source("{0}", DRC=1)</Value>
</Radiobutton>
<Radiobutton Name="NicAc3Source (Down2)">
<Value>NicAc3Source("{0}", 2)</Value>
</Radiobutton>
<Radiobutton Name="NicAc3Source (Down2, DRC)">
<Value>NicAc3Source("{0}", 2, DRC=1)</Value>
</Radiobutton>
</MultiOptionSource>

Of course you can activate these options in your scripts like you can read in the wiki (http://avisynth.nl/index.php/NicAudio)

Edit: could activating DRC be done in compression mode given certain parameters? I have this doubt aside.

If you talk about free AC3 encoders (Aften, ffmpeg) the answer is nope. You need any commercial Dolby encoders.

The DRC present in AC3 stream was needed longtime ago when AVR's aren't with power process.
Now the AVR's can do DRC on the fly with functions like 'Night mode' and not only over AC3 streams.
Then DRC in streams are useless now.

tebasuna51
25th June 2021, 12:18
I have downloaded the sourcecode from BeHappy and i have modified some things for me.

Of course you can customize BeHappy at your taste, but the option to don't apply DRC is the default and it is not necesary modify nothing to downloaded soft.

Also i have integrated the newest Timestretch Plugin from Avisynth+ 3.7.0.

Please explain me how, because BeHappy generate TimestretchPlugin() calls (to Timestretch.dll 2015 Wilbert (http://avisynth.nl/index.php/External_filters#Audio_Filters)) but Timestretch.dll avs+ need calls with only Timestretch() like internal Timestretch functions in standard avs.

GMJCZP
25th June 2021, 16:12
Thank you both for your answers. Since I hardly used my PC in these last years I still feel rusty on some things, I need to review / learn and update myself on these things.

tebasuna, one of the things that I wanted to improve is to apply compression to audios with abrupt changes in volume, as in movies, what several cable channels (at least in Latin America) do (is what I notice). I have done this with Adobe Audition but I feel it can be done even better, maybe in BeHappy.

So my question: Could DRC be applied to any type of audio with BeHappy, if possible with parameters, that is, not only automatically?

-QfG-
25th June 2021, 19:28
DRC (Dynamic Range Compression) is a Decoder thing, not Encoder thing. DRC is an information in the AC3 Audio File. FFMPEG can delete this information with the FFMPEG Decoder (-drc_scale 0). But now the problem, if u work with a frameserver and tunneling your AVS script, FFMPEG cannot decode the AC3 file, you must do this with the frameserver, btw. indexer. NicAudioSource is the only indexer i found, that can do this. So i can't encode an audio file directly from a container without DRC. I have created a batch script for this operation. But i will check FFAudioSource, i hope this has an DRC0 function.

This is included formally in Behappy in s_NicAudio.ext

I have not testet this, i've forced DRC OFF with the ", DRC=0" Switch and this works fine for me.

Please explain me how, because BeHappy generate TimestretchPlugin() calls (to Timestretch.dll 2015 Wilbert) but Timestretch.dll avs+ need calls with only Timestretch() like internal Timestretch functions in standard avs.

I have downloaded the sourcecode from Github and modified it. Here is my compiled updated BeHappy with Avisynth 3.7.x Support (https://1fichier.com/?w4hxlyrqfqmxwv3c0gvt).

Could DRC be applied to any type of audio with BeHappy, if possible with parameters, that is, not only automatically?

Nope, only AC3 files can be DRC compressed. I don't know why BeHappys NicDTSSource has the DRC Parameter.

GMJCZP
25th June 2021, 21:11
Ok, I understand, now I will put my request in another way, avoiding the term DRC: in Adobe Audition there is a way to compress (or expand) any audio. In the specific case of compression, I would like to know if it is possible in BeHappy to add a compressor for those sounds with large volume variations?

tebasuna51
25th June 2021, 22:01
But i will check FFAudioSource, i hope this has an DRC0 function.
Still not, I make a feature request in precedent post.

I have downloaded the sourcecode from Github and modified it.
Thanks, I'll try it.

I don't know why BeHappys NicDTSSource has the DRC Parameter.
DTS files can have also DRC data (from DTS Coherent Acoustics):

Embedded Dynamic Range Flag
DYNF indicates if embedded dynamic range coefficients are included at the start of each sub-frame. Dynamic range correction may be implemented on all channels using these coefficients for the duration of the sub-frame.

tebasuna51
25th June 2021, 23:11
I would like to know if it is possible in BeHappy to add a compressor for those sounds with large volume variations?

That is an AviSynth plugin (BeHappy only work with avs filters).

You have the SoxFilter, it have some problems but you can try the compand function, for instance some samples here https://forum.doom9.org/showthread.php?p=779165#post779165

But I recommend you use ffmpeg better.

GMJCZP
26th June 2021, 04:39
But I recommend you use ffmpeg better.

Thank you very much tebasuna.

If it's not too much to ask, how can compression be done with FFMpeg?

tebasuna51
26th June 2021, 10:03
If it's not too much to ask, how can compression be done with FFMpeg?

There are many filters:

- Also the compand, like with sox, https://ffmpeg.org/ffmpeg-filters.html#compand , a example here (https://forum.doom9.org/showthread.php?p=1926777#post1926777)
And with selection of frequency bands https://ffmpeg.org/ffmpeg-filters.html#mcompand

- A similar compressor (I don't know the sources) https://ffmpeg.org/ffmpeg-filters.html#acompressor

- A EBU R128 loudness normalization https://ffmpeg.org/ffmpeg-filters.html#loudnorm

- At last, but maybe the recommended, https://ffmpeg.org/ffmpeg-filters.html#dynaudnorm
I think is the method created by LoRd_MuldeR explained here (https://forum.doom9.org/showthread.php?p=1688950#post1688950) and with links to standalone filter.

-QfG-
26th June 2021, 11:40
A little Update of my modified BeHappy Version:

-Output as Dolby TrueHD (LOSLESS) available.

https://1fichier.com/?pk9l96pmlzarib9akme2

GMJCZP
26th June 2021, 11:59
There are many filters:

- Also the compand, like with sox, https://ffmpeg.org/ffmpeg-filters.html#compand , a example here (https://forum.doom9.org/showthread.php?p=1926777#post1926777)
And with selection of frequency bands https://ffmpeg.org/ffmpeg-filters.html#mcompand

- A similar compressor (I don't know the sources) https://ffmpeg.org/ffmpeg-filters.html#acompressor

- A EBU R128 loudness normalization https://ffmpeg.org/ffmpeg-filters.html#loudnorm

- At last, but maybe the recommended, https://ffmpeg.org/ffmpeg-filters.html#dynaudnorm
I think is the method created by LoRd_MuldeR explained here (https://forum.doom9.org/showthread.php?p=1688950#post1688950) and with links to standalone filter.

Thanks, I'll take a look at it.

tebasuna51
26th June 2021, 16:06
A little Update of my modified BeHappy Version:

-Output as Dolby TrueHD (LOSLESS) available.

Works fine for me.

Like I have my install also customized I only replace the BeHappy.exe and is OK.
I see you add also the ConvertAudioToFloat() before (needed in Avs+), and can be compatible with Avs 2.61 also.

I add a link in BeHappy thread (https://forum.doom9.org/showthread.php?p=1946110#post1946110), thanks.