View Full Version : changing audiodub() a bit
esby
13th August 2005, 22:47
Actually audiodub will throw an avisynth exception
if the clip used to get the audio has no audio track,
which is normal, but sometimes, when you write generic scripts,
you just want to be sure that the audio is conserved separately, supposing there is one.
The answer to this little problem would be just that if there is no audio in the audio clip, the resulting clip would have no audio. (Which should be somewhat normal after all.)
esby
Wilbert
14th August 2005, 00:02
About your question on IRC. I looked at the source from 'avs v2.50' (it hasn't changed since then):
// edit.cpp
AudioDub::AudioDub(PClip child1, PClip child2, IScriptEnvironment* env)
{
const VideoInfo& vi1 = child1->GetVideoInfo();
const VideoInfo& vi2 = child2->GetVideoInfo();
const VideoInfo *vi_video, *vi_audio;
if (vi1.HasVideo() && vi2.HasAudio()) {
vchild = child1; achild = child2;
vi_video = &vi1, vi_audio = &vi2;
} else if (vi2.HasVideo() && vi1.HasAudio()) {
vchild = child2; achild = child1;
vi_video = &vi2, vi_audio = &vi1;
} else {
env->ThrowError("AudioDub: need an audio and a video track");
}
(...)
}
So one clip should contain video (doesn't matter which one) and the other audio, otherwise it will throw an exception.
Perhaps in your succeeded attempt the audio was taken from the first clip and the video from the second?
mg262
14th August 2005, 00:03
That could probably be dealt with by a script function... I can't find in the documentation and direct way to check for audio, but there are several methods that would probably work... I haven't checked whether
Audiochannels (clip)
returns 0 if there is no audio, but it's an example. You could then use the ? : operator to build a function that did what you want.
Edit:
@Wilbert,
I think it was a request for the function to be changed so that it didn't return an error message when there was no audio track present (for situations where an unknown clip, possibly containing audio and possibly not, was fed into a script function).
Wilbert
14th August 2005, 00:05
I can't find in the documentation and direct way to check for audio
HasAudio(...)
This should be in syntax.htm somewhere.
mg262
14th August 2005, 00:08
HasAudio(...)
This should be in syntax.htm somewhere.
Thank you... I just tried using find in syntax.htm and it doesn't turn up HasAudio... (I'm using version 2.55).
Wilbert
14th August 2005, 00:31
That makes sense, because they were made available to the users in v2.56b2 :)
squid_80
14th August 2005, 01:46
I haven't checked whether
Audiochannels (clip)
returns 0 if there is no audio, but it's an example. You could then use the ? : operator to build a function that did what you want.
You know, I can remember doing this once and it didn't work - I tried to figure out what was happening by using info(), and it said Has Audio: NO, Audio Channels: 2156 or some random number like that. I guess the value for audio channels wasn't being initialized properly by some filter, but now I can't remember which one.
esby
14th August 2005, 21:35
Well for the audioDub() part.
function audiodubExt(clip video, clip audio)
{
return hasAudio(audio) ? audioDub(video,audio) : video
}
works fine.
The typical use case I was referring is:
video = avisource("test.avi").convertTorgb32()#.killaudio()
img = imagesource("image.png",100, 199, 29.97)
img = img.assumefps(video).convertTorgb32()
audioGate = video
video = video.killaudio()
video = video ++ img
return audiodubExt(video,audioGate)
Now for the Audiochannels (clip) part.
Avisynth uses the number of audio samples per second to determine if a clip has audio or not.
If it is equal to zero, it means no audio.
So checking for Audio Channels number will not work, since it is not initialized according to this way.
esby
IanB
15th August 2005, 11:54
@Esby,
Yes, I have been often annoyed by this, I just might do this.
IanB
Edit: Just commited to CVS. Look for AudioDubEx() in the next release, it blindly merges the VI's from the Video and Audio donor clips even if they don't have video and/or audio respectively.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.