Log in

View Full Version : avisynth audio processing problem (vbr mp3...)


Buzz Lightyear
8th November 2008, 18:05
I'm converting an avi file (xvid/vbr mp3) to mp4 (x264/aac) and use this script for audioprocessing:

test.avs
AviSource("clip.avi")

and then run the whole thing through wavi and neroaac

.\wavi\wavi.exe "test.avs" - | ".\nero\neroAacEnc.exe" -ignorelength -he -br 96000 -if - -of "audio.mp4"

This works fine, but the encoded aac is always the wrong length.
For example: the avi has 1300 seconds. When I demux the mp3 with VDubMod the mp3 has also 1300 seconds.
But when I run my script, the audio has suddenly 1385 seconds (with 85 seconds silence at the end). The audio is NOT out of sync, it's just the wrong lenght.
I've tried different source files, and sometimes the aac is too long (with silence at the end), and sometimes the aac is cut off at the end by a couple of seconds.

I've tried reinstalling avisynth. I've tried "ensureVBRMp3Sync()" in the avs. I've tried "OpenDMLSource()" instead of "avisource()". But nothing helped.
The annoying thing is, that my script used to work fine half a year ago, but now something somehow is broken.
Does anyone have an idea, what else I could try? I'm really lost here.

Regards
Buzz

buzzqw
8th November 2008, 18:07
with directshowsource you got the same issue ?

BHH

setarip_old
8th November 2008, 20:53
@Buzz Lightyear

Hi!

I've got to believe that it would be far easier - and certainly would result in higher quality output - if you used your hard drive rip of your original source material (Presumably, a commercial DVD) to create your desired MP4 file...

kemuri-_9
8th November 2008, 21:37
for vbr mp3's i usually find it best to demux the mp3 out of the avi and use LAME's cli interface to decode it to .wav directly,
any other mp3 decoder (winamp, foobar, w/e) that can decode it to wav should be ok as well.
then use the .wav in your audio encoder, neroaacenc in this case.

tebasuna51
8th November 2008, 22:01
Always demux first (VirtualDubMod) the mp3, and use a decoder with support for VBR.
Download NicAudio.dll plugin and try this avs:
NicMPG123Source("clip.mp3")

Is know than avi don't support VBR audio.

Wilbert
9th November 2008, 17:38
Is know than avi don't support VBR audio.
AVI can handle VBR audio fine.

tebasuna51
9th November 2008, 20:11
Here is the problem:

When AViSynth open an audio need know:
- The num_channels
- The sample_type (int 8/16/24/32 or float 32)
- The samplerate (audio_samples_per_second)
- The num_audio_samples

The num_audio_samples can't be know exactly without scan all the stream if the bitrate is VBR, then sometimes the initial aproach is lower or greater than the exact number. If is lower the audio is cut, if is grater the audio is filled with silence.

NicMPG123Source() function need scan all the mp3 file, at the beginning, to know the exact num_audio_samples and output the correct audio length.

Seems the avi header don't inform about the exact audio duration or AviSynth can't acces to it.

@Wilbert, I'm not a video expert but I see many problems with that, and VirtualDub boys warn about the use of VBR audio in avi.

kemuri-_9
9th November 2008, 22:16
vbr audio in avi does work,
it's just problematic when editing videos
(as you can tell with all the desyncage that occurs)
so to maintain sync when editing, it's best to decode the audio beforehand.

IanB
9th November 2008, 22:20
For ACM compressed audio streams the number of audio samples is calculated from audio wave header in the avi file header :-

uncompressed_stream_len = compressed_stream_len * nSamplesPerSec * nBlockAlign / nAvgBytesPerSec

Various and sundry programs do not put the truth, the whole truth and nothing but the whole truth into these values. And even for those that get it right it is still possible to be out by upto (nAvgBytesPerSec-1) samples due to division truncation.

As tebasuna51 points out for VBR audio streams you need to parse them first to get the exact uncompressed sample count.

Buzz Lightyear
9th November 2008, 22:41
Thanks for all the replies.
I think I found the solution. I changed from avisource to directshowsource + ensurevbrmp3sync. (only directshowsource alone doesn't work since it can't handle vbr-mp3 properly. audio gets out of sync)
I just tried it on one avi file, which didn't work before, but now works fine. Will try all the other files I want to convert tomorrow.

But what i still didn't understand is, why i got this problem in the first place. This way of audio processing has worked flawlessly on 50+ files that i converted several months ago. And now suddenly audio was alway cropped or too long, with EXACTLY the same script..... :confused:

Update:
Tried directshowsource + ensurevbrmp3sync with ~10 other avi file. Everything works fine now.
Thanks again for the help!
I will also update my (super sophisticated ;) ) batch script here: http://forum.doom9.org/showthread.php?t=129415