Log in

View Full Version : AudioDub invalid arguments


AlexeyS
27th March 2009, 11:46
Hello guys,

I'm trying to merge small video logo and mpeg2 file with avisynth:

logo = AviSource("E:\fr\logo-effects-43.avi")
logo.Crop(0,24,0,-24)
movie = MPEG2Source("E:\fr\vts_02_1.d2v")
movie.Crop(8,0,-8,-0)
movie.Lanczos4Resize(720,528)
movieAudio = DirectShowSource("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3")
movie.AudioDub(movie, movieAudio)
return logo + movie

When I try to use this script, I get error message:
Invalid argument to function Audiodub

I wonder how can I fix it?

PS: Movie is SD MPEG2 (VOB) with AC3 audio. Logo is uncompressed AVI with PCM audio.

Gavino
27th March 2009, 12:22
The immediate source of the error is that
movie.AudioDub(movie, movieAudio)
is equivalent to
AudioDub(movie, movie, movieAudio)
so invalid arguments (3 clips instead of 2)

But you also need to understand that a statement like logo.Crop(0,24,0,-24) does not alter the variable 'logo' - if you want to do that you need to assign the result back to the variable. So your script should be as follows:
logo = AviSource("E:\fr\logo-effects-43.avi")
logo = logo.Crop(0,24,0,-24)
movie = MPEG2Source("E:\fr\vts_02_1.d2v")
movie = movie.Crop(8,0,-8,-0)
movie = movie.Lanczos4Resize(720,528)
movieAudio = DirectShowSource("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3")
movie = AudioDub(movie, movieAudio)
return logo + movie

AlexeyS
27th March 2009, 12:35
The immediate source of the error is that
movie.AudioDub(movie, movieAudio)
is equivalent to
AudioDub(movie, movie, movieAudio)
so invalid arguments (3 clips instead of 2)

But you also need to understand that a statement like logo.Crop(0,24,0,-24) does not alter the variable 'logo' - if you want to do that you need to assign the result back to the variable. So your script should be as follows:
logo = AviSource("E:\fr\logo-effects-43.avi")
logo = logo.Crop(0,24,0,-24)
movie = MPEG2Source("E:\fr\vts_02_1.d2v")
movie = movie.Crop(8,0,-8,-0)
movie = movie.Lanczos4Resize(720,528)
movieAudio = DirectShowSource("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3")
movie = AudioDub(movie, movieAudio)
return logo + movie
Thanks for quick reply and explanation.

I've tried this code, but I get error:
Splice: Video formats don't match

I wonder how can I fix it?

I've tried to add:
movie = movie.ConvertToRGB
logo = logo.ConvertToRGB

But it seems problem is in something else.

Gavino
27th March 2009, 18:21
Splice: Video formats don't match

I've tried to add:
movie = movie.ConvertToRGB
logo = logo.ConvertToRGB

That should work. What error do you now get?

An alternative would be to add just
logo = logo.ConvertToYV12()
(assuming movie is already in YV12 format, since it's MPEG2).

AlexeyS
27th March 2009, 18:58
That should work. What error do you now get?

An alternative would be to add just
logo = logo.ConvertToYV12()
(assuming movie is already in YV12 format, since it's MPEG2).
logo = logo.ConvertToYV12() works. Thanks.

Now I get error "Video frarate doesn't match". I've read FPS filter manual and added ConvertFPS to my script:

logo = AviSource("E:\fr\logo-effects-43.avi")
logo = logo.Crop(0,24,0,-24)
logo = logo.ConvertFPS(29.970)
movie = MPEG2Source("E:\fr\vts_02_1.d2v")
movie = movie.TomsMoComp(-1, 15, 1)
movie = movie.Crop(8,0,-8,-0)
movie = movie.Lanczos4Resize(720,528)
movieAudio = DirectShowSource("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3")
movie = AudioDub(movie, movieAudio)
logo = logo.ConvertToYV12()
return logo + movie

But it still gives same error about frame rate.

I've looked into MPEG2 and it's 29.970, so I don't what's wrong here.

Could you help me with that too. Sorry for a lot of questions, but I'm merging files with AviSynth for the first time.

stickboy
27th March 2009, 20:39
Just because the MPEG2 file reports itself to be 29.970 fps doesn't mean that it's exactly 29.970 fps. There can be rounding error. Also, I think AviSynth might try to interpret 29.970 in the ConvertFPS call to mean 30000/1001 (which is more correct anyway).

If you want the logo clip to exactly match the FPS of the movie clip, you should use:
logo.AssumeFPS(movie)

AlexeyS
27th March 2009, 21:10
Just because the MPEG2 file reports itself to be 29.970 fps doesn't mean that it's exactly 29.970 fps. There can be rounding error. Also, I think AviSynth might try to interpret 29.970 in the ConvertFPS call to mean 30000/1001 (which is more correct anyway).

If you want the logo clip to exactly match the FPS of the movie clip, you should use:
logo.AssumeFPS(movie)
Thanks. It works, but it seems it adds the problem with audio desync.

Video now have audio delay something like 0.4-0.7 seconds.

Maybe AssumeFPS converts FPS of the logo video and leaves audio as is? Or something like that?

Gavino
27th March 2009, 21:56
Try using AlignedSplice (++) instead of UnalignedSplice (+), ie
return logo ++ movie

AlexeyS
27th March 2009, 22:02
Try using AlignedSplice (++) instead of UnalignedSplice (+), ie
return logo ++ movie
Didn't help.

Umamio
28th March 2009, 00:42
You need to specify in AssumeFPS that you want to keep the audio synchronised:

i.e:
logo = logo.AssumeFPS(movie,true).ResampleAudio(48000)
return logo++movie

Does that change anything?

AlexeyS
28th March 2009, 11:34
You need to specify in AssumeFPS that you want to keep the audio synchronised:

i.e:
logo = logo.AssumeFPS(movie,true).ResampleAudio(48000)
return logo++movie

Does that change anything?
Nope, audio still delays.

The currents script is:
logo = AviSource("E:\fr\logo-effects-43.avi")
logo = logo.Crop(0,24,0,-24)
movie = DirectShowSource("E:\fr\vts_02_1.vob")
movie = movie.TomsMoComp(-1, 15, 1)
movie = movie.Crop(8,0,-8,-0)
movie = movie.Lanczos4Resize(720,528)
logo = logo.ConvertToYV12()
movie = movie.ConvertToYV12()
logo = logo.AssumeFPS(movie, true).ResampleAudio(48000)
return logo ++ movie

Umamio
28th March 2009, 12:04
The audio desync culprit might be DirectShowSource, when did you change from Mpeg2Source to DirectShowSource?

Anyway, if they do not already exist in your avisynth plugins folder (Default C:\Program Files\AviSynth 2.5\plugins, on Windows):
- Put DGdecode.dll (http://neuron2.net/dgmpgdec/dgmpgdec.html) in your plugins folder
- Put NicAudio.dll (http://nic.dnsalias.com/nixaudiostuff.html) in your plugins folder

and then try


logo = AviSource("E:\fr\logo-effects-43.avi")

MovieV = DGdecode_Mpeg2Source("E:\fr\vts_02_1.d2v", info=3)#.Colormatrix(hints=true)
MovieA = NicAC3Source("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3", channels=logo.AudioChannels)
movie = AudioDub(MovieV, MovieA)
movie = movie.TomsMoComp(-1, 15, 1)
movie = movie.Crop(8,0,-8,-0)
movie = movie.Lanczos4Resize(720,528)
movie = movie.ConvertToYV12()

logo = logo.Crop(0,24,0,-24)
logo = logo.AssumeFPS(movie, true).ResampleAudio(movie.Audiorate)
logo = logo.convertToYV12

return logo++movie

Does that work?

Edit: Modified Script
This assumes you want the number of audio channels in the movie to match the channels in the logo, rather than the other way around.

I assumed so only because it's a lot easier to reduce the number of audio channels from an ac3 in avisynth than it is to increase the number of channels from a PCM source.

If you want the logo to change itself to match the movie in all ways, gzarkadas and Gavino helped me debug some simple functions I wrote a while ago that do exactly that. I will post it for you once I've made it more generalised / less specific to my needs, if you like.

AlexeyS
28th March 2009, 12:37
The audio desync culprit might be DirectShowSource, when did you change from Mpeg2Source to DirectShowSource?

Anyway, if they do not already exist in your avisynth plugins folder (Default C:\Program Files\AviSynth 2.5\plugins, on Windows):
- Put DGdecode.dll (http://neuron2.net/dgmpgdec/dgmpgdec.html) in your plugins folder
- Put NicAudio.dll (http://nic.dnsalias.com/nixaudiostuff.html) in your plugins folder

and then try


logo = AviSource("E:\fr\logo-effects-43.avi")

MovieV = DGdecode_Mpeg2Source("E:\fr\vts_02_1.d2v", info=3)#.Colormatrix(hints=true)
MovieA = NicAC3Source("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3", channels=logo.AudioChannels)
movie = AudioDub(MovieV, MovieA)
movie = movie.TomsMoComp(-1, 15, 1)
movie = movie.Crop(8,0,-8,-0)
movie = movie.Lanczos4Resize(720,528)
movie = movie.ConvertToYV12()

logo = logo.Crop(0,24,0,-24)
logo = logo.AssumeFPS(movie, true).ResampleAudio(movie.Audiorate)
logo = logo.convertToYV12

return logo++movie

Does that work?

Edit: Modified Script
Error: Number of channels doesn't match.

Logo has 2 channels. And .vob 5 channels as MediaInfo says (BTW is it normal? I thought DVD has 5.1 which is 6 channels).

AlexeyS
28th March 2009, 12:38
gzarkadas and Gavino helped me debug some simple functions I wrote a while ago that do exactly that. I will post it for you once I've made it more generalised / less specific to my needs, if you like.
Yes, it would be great.

Umamio
28th March 2009, 14:40
Did you get the audio channels problem even with this line?

MovieA = NicAC3Source("E:\fr\vts_02_1 T81 3_2ch 384Kbps DELAY 0ms.ac3", channels=logo.AudioChannels)

I edited it a few minutes after I originally posted.

AlexeyS
28th March 2009, 21:00
Perfect. :)

Thanks A LOT guys, I really appreciate your help.

We get pretty big script. :)