Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd July 2015, 07:03   #1  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
AviSynth behavior for redundant commands

In the past I have learned that for example the command "ConvertToYV12()" will be completely ignored if the clip already has this color space. Very nice because I can freely use this command without having to know the color space of the source.

Now what about some audio conversion commands?

Will "ConvertAudioTo24Bit()" do anything if audio already is 24bit?
What about "ResampleAudio(xxxx)" or "SSRC(xxxx)" if the clip already has this sample rate?


Cheers
manolito
manolito is offline   Reply With Quote
Old 2nd July 2015, 07:18   #2  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
AviSynth 2.6:
Quote:
Originally Posted by manolito View Post
Will "ConvertAudioTo24Bit()" do anything if audio already is 24bit?
No.

Quote:
Originally Posted by manolito View Post
What about "ResampleAudio(xxxx)" or "SSRC(xxxx)" if the clip already has this sample rate?
Both of them output float, so there will be a change unless input is also float. Which I think should not happen, i.e. might be considered a bug.
sneaker_ger is offline   Reply With Quote
Old 2nd July 2015, 09:43   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by sneaker_ger View Post
Both of them output float, so there will be a change unless input is also float.
For ResampleAudio(), 16-bit input is preserved, and not converted to float.
So if the target rate is the same as the original rate, the function is a no-op for 16-bit input.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 2nd July 2015, 09:49   #4  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Yes, it seems only 24 bit and 32 bit integer are affected with ResampleAudio(). But all three formats are affected with SSRC().

Last edited by sneaker_ger; 2nd July 2015 at 09:54.
sneaker_ger is offline   Reply With Quote
Old 2nd July 2015, 10:31   #5  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Thanks a lot guys, very helpful...

The reason I was asking is my Wavi_Mod plugin for AVStoDVD which enables alternative methods for audio normalizing (SoX, EBU R128, DynamicAudioNormalizer).

It uses either pipes or temp files, and I figured it could be useful to generally employ 24bit integer intermediate WAVE files. LAV audio is used as the source filter, and it mostly decodes as 32bit float (unless the user has disabled some output formats). But the Wavi output is always integer, probably because AVStoDVD is written in VB6 which probably uses AviSynth through the VfW interface which does not support float.

So my idea is to always append "ConvertAudioTo24Bit" to the end of the AviSynth script. This should make sure that no precision is lost when the format would be 32bit float like after SSRC. (Got this from an older post from Gavino). Does this sound reasonable? Or is it just a waste of time since the final format will be AC3 ?


Thanks again
manolito

Last edited by manolito; 2nd July 2015 at 10:34.
manolito is offline   Reply With Quote
Old 2nd July 2015, 10:37   #6  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
I don't understand what you're trying to achieve. How is adding an additional conversion at the end of a chain making sure no precision is lost? There are only three cases:
1. input into ConvertAudioTo24Bit() is 16 bit: will be skewed to 24 bit, no additional precision, just a useless conversion
2: input into ConvertAudioTo24Bit() is 24 bit: no change
3: input into ConvertAudioTo24Bit() is 32 bit integer or float: loss of precision
sneaker_ger is offline   Reply With Quote
Old 2nd July 2015, 13:16   #7  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Quote from tebasuna:
Quote:
Then at least 24 int is recommended, similar precission than 32 float.
Quote from Gavino:
Quote:
SSRC() returns float audio.
If Avisynth is being used through the VfW interface, this is converted to 16 bit as VfW does not support float.

Add ConvertAudioTo24Bit() to the end of your script to force retention of 24 bits.

In AVStoDVD you can never know in advance which bit depth Wavi will get from AviSynth. If the input from LAV audio is 32 bit float or if SSRC() is used within AviSynth, the Wavi output will be 16 bit integer. In these cases forcing 24 bit integer makes sense IMO.


Your three cases:
1. Useless yes, but at very low cost in terms of speed.
2. Yes
3. Since float is not supported and would normally get converted to 16 bit integer, forcing 24 bit integer should (almost) preserve the precision according to tebasuna.

Of course I could first analyze what Wavi would output without interfering and then decide if I need to force 24 bit integer, but why should I do this if forcing 24 bit no matter what has no disadvantage?


Cheers
manolito
manolito is offline   Reply With Quote
Old 2nd July 2015, 13:22   #8  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Ah, I missed the part about Wavi. Well, if you have to continue using such limited software I think it's ok. You do of course get precision loss but I assume not enough to be audible.
sneaker_ger is offline   Reply With Quote
Old 2nd July 2015, 17:05   #9  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Quote:
Originally Posted by sneaker_ger View Post
Ah, I missed the part about Wavi. Well, if you have to continue using such limited software I think it's ok.
Do you have a suggestion for a Wavi replacement? As I see it the latest version 1.06m does everything to extract a WAVE file from AviSynth at the highest possble quality, and it is absolutely stable.
Quote:
1.04: added support for floating-point samples (thanks to tebasuna51)
And Wavi does support float samples, the downconversion to 16 bit int is done by AviSynth, not by Wavi.

Do you think that SoundOut or ffmpeg would do a better job? And there is another requirement: The tool must support large WAVE files > 4GB. I am not talking about WAV EXTENSIBLE or WAV 64 since these formats are not supported by SoX and Aften. I would need the standard WAV format (but larger than the standard allows). No problem for Wavi...


Cheers
manolito

Last edited by manolito; 2nd July 2015 at 17:15.
manolito is offline   Reply With Quote
Old 2nd July 2015, 17:34   #10  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
avs2pipemod
sneaker_ger is offline   Reply With Quote
Old 2nd July 2015, 18:01   #11  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Thanks for the suggestion...

Had a quick look at it, but compared to Wavi the capabilities are overkill, and here's the showstopper:
Quote:
audio - output wav extensible format audio to stdout
Sure this is more up to date than Wavi, but I have to feed the WAVE (as a file or by piping) to Aften and/or SoX, and both cannot deal with WAVEFORMATEXTENSIBLE.

So I will stick with Wavi...


Cheers
manolito
manolito is offline   Reply With Quote
Old 2nd July 2015, 18:30   #12  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
avs2pipemod does both WAVEFORMATEX and WAVEFORMATEXTENSIBLE and works fine here with SoX:
avs2pipemod -wav input.avs | SoX -t wav - output.wav
sneaker_ger is offline   Reply With Quote
Old 2nd July 2015, 19:14   #13  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,419
At least the way I'd understand it, AVStoDVD *should* be passing the script to the particular programs (where applicable), therefore whatever the program does to access AviSynth would matter more than whether AVStoDVD itself might use the VfW interface to talk to scripts. For FFmpeg this would mean accessing the library directly and - if using -acodec copy - getting out exactly whatever the audio format output from the script is.

Code:
ffmpeg -i input.avs -acodec copy output.wav
If the script outputs 16-bit integer, output.wav will be pcm_s16le. If it output 24-bit integer, it'll be pcm_s24le. If it output float, it'll be pcm_f32le. It's just copying the PCM samples output from AviSynth directly to the output file.


Quote:
Originally Posted by manolito
I am not talking about WAV EXTENSIBLE or WAV 64 since these formats are not supported by SoX and Aften.
FFmpeg writes WAVE_FORMAT_EXTENSIBLE headers for 24-bit and Float output, but not for 16-bit.

For Aften, you can work around this using qaac as a passthrough:
Code:
ffmpeg -i test.avs -acodec copy -f wav - | qaac --silent -D - -o - | aften - output.ac3
(forcing -f wav is necessary so aften doesn't puke)

SoX and Aften do support WAVE_FORMAT_EXTENSIBLE, but not when piped by FFmpeg (this is discussed in this thread - the short version: some programs don't like the way FFmpeg writes the WAVE headers when piping). A standalone file with an extensible header does work, although I was testing with 30-second samples.

An alternative is to force FFmpeg to use a different format to pipe to SoX. WavPack works (and from how the docs read, the native libavcodec wavpack encoder only does lossless):
Code:
ffmpeg -i test.avs -acodec wavpack -f wv - | sox -t wv - output.wav

Although as sneaker_ger pointed out, avs2pipemod seems to handle this correctly without resorting to qaac passthrough tricks or using alternative pipe formats.
qyot27 is offline   Reply With Quote
Old 3rd July 2015, 04:22   #14  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Quote:
Originally Posted by qyot27 View Post
SoX and Aften do support WAVE_FORMAT_EXTENSIBLE
Yes, looks like it. So for the sake of completeness avs2pipemod's WAVEFORMATEXTENSIBLE:
avs2pipemod -extwav input.avs | SoX -t wav - output.wav

I also remember having trouble with ffmpeg->sox pipes now that you mention it. I think Hybrid uses headerless PCM piping for that reason.
sneaker_ger is offline   Reply With Quote
Old 3rd July 2015, 07:43   #15  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Thanks guys,

you gave me a couple of ideas to rewrite my plugin to use the extensible wave format exclusively.

AVStoDVD can already use ffmpeg to extract a wave file from the avs script, but the wave is always 16 bit int. Took me a while to find out that the reason for this is that "-acodec copy" is missing from the command line.

Wavi always extracts 16 bit int wav files when the format is 32 bit float (even though the changelog says that it supports float).


Cheers
manolito
manolito is offline   Reply With Quote
Old 6th July 2015, 08:06   #16  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
Quote:
Originally Posted by manolito View Post
Wavi always extracts 16 bit int wav files when the format is 32 bit float (even though the changelog says that it supports float).
Nope, wavi support 32 bit float without problems.

Is a AviSynth default than need be canceled with, for instance in a test.avs:

global OPT_AllowFloatAudio=True # enables WAVE_FORMAT_IEEE_FLOAT audio output.
NicAc3Source("D:\tmp\200.ac3") # Decoder output is 32 bits float

And:
wavi test.avs output.wav

Found PCM audio: 2 channels, 48000 Hz, 32 bits,
Audio track contains floating-point samples.

EDIT: Other soft like MeGUI or BeHappy don't need 'global OPT_AllowFloatAudio=True' because a special AvisynthWrapper.dll
__________________
BeHappy, AviSynth audio transcoder.

Last edited by tebasuna51; 6th July 2015 at 08:14. Reason: add info
tebasuna51 is offline   Reply With Quote
Old 6th July 2015, 13:11   #17  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Thanks very much Tebasuna...

I did not even know that this AviSynth command even existed.
Question: Why is this command only needed for Wavi, but not for ffmpeg and avs2pipemod?

And since I'm at it: What is your opinion on the preferred intermediate WAV resolution for DVD audio conversion (I am not talking about professional audio recording and mixing/mastering).

I did quite a lot of reading about this topic in the audio forums, and there are different opinions. Most people say that 24bit int is more resolution than anyone will ever need, others say that the better clipping protection which float offers is indeed worth the trouble.


Cheers
manolito
manolito is offline   Reply With Quote
Old 6th July 2015, 13:37   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Manolito,
OPT_AllowFloatAudio, occurs @ Avisynth Syntax/Internal Functions/Control Functions,
in Avisynth built-in docs, with a few more 'secret' bits and pieces.

EDIT: Or here on wiki:- http://avisynth.nl/index.php/Interna...llowFloatAudio
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 6th July 2015 at 13:46.
StainlessS is offline   Reply With Quote
Old 6th July 2015, 18:20   #19  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Thanks for the tips,

just tried it with several sources, it works, but only if the global OPT_AllowFloatAudio=True comes at the beginning of the AVS script.

I first tried to append the command to the end of the script (after the "audiodub(video,audio)" command), but this did not work. Wavi would then complain that no PCM audio could be found at all.


//EDIT//
The global OPT_AllowFloatAudio=True does not need to be at the very beginning of the script, but it does need to come before the "audiodub(video,audio)" statement. And it also works if the "global" is omitted.


Cheers
manolito

Last edited by manolito; 7th July 2015 at 07:59.
manolito is offline   Reply With Quote
Old 19th July 2015, 20:23   #20  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Bumping this thread because the global OPT_AllowFloatAudio=True command does not work as expected for me...

From the ALLOW I assumed that the audio output will be float only if the source filter delivers float samples. But instead the command seems to FORCE float audio no matter what.

I disabled all audio formats except 8bit int in the LAV Audio settings. The LAV status window correctly reports the input format as 32bit float aac and the output format as 8bit int PCM. But with the "global OPT_AllowFloatAudio=True" present in the AVS script the audio output from AviSynth is 32bit float.

This means that AviSynth actively converts 8bit int audio samples as delivered by the source filter to 32bit float - which of course does not make much sense.

Can anyone confirm this behavior?


Cheers
manolito
manolito is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:10.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.