PDA

View Full Version : Need help with fadein/out


Swan
19th August 2003, 09:55
I am trying to write a simple script that will fade the video, but not the audio, at the same time maintaining audio/video sync (since fadein adds one black frame). This is what I've been using:

video = AviSource("test.avi")
audio = WavSource("test.wav")
video = fadein(video, 25)
video = fadeout(video, 50)
audio = delayaudio(audio, 0.04)
video = letterbox (video, 0,14,12,0)
audiodub(video,audio)

The above doesn't fade the audio, but the delayaudio is cumbersome.
It seems more intelligent to dub audio and video together, before
adding the fade. Is that possible?
If I could add the audiodub(video,audio) line before
the fade commands, the audio = delayaudio(audio, 0.04) line would not be necessary, right?

But this:
video = AviSource("test.avi")
audio = WavSource("test.wav")
audiodub(video,audio)
video = fadein(video, 25)
video = fadeout(video, 50)
video = letterbox (video, 0,14,12,0)
Gives me an error message: "Avisynth Open Failure: the script's return value was not a video clip".

So I add the word video at the end, like this:
video = AviSource("test.avi")
audio = WavSource("test.wav")
audiodub(video,audio)
video = fadein(video, 25)
video = fadeout(video, 50)
video = letterbox (video, 0,14,12,0)
video

This script works. But the audio is faded along with the video..

Wilbert
19th August 2003, 10:02
Your script doesn't work, because the audiodub line isn't passed through. Change it in:

video = AviSource("test.avi")
audio = WavSource("test.wav")
audiodub(video,audio)
fadein(25)
fadeout(50)
letterbox(0,14,12,0)

Swan
19th August 2003, 10:10
Wilbert, thanks. But your suggestion fades the audio...

stickboy
19th August 2003, 10:11
According to the manual, FadeIn(c, n) and FadeOut(c, n) are equivalent to:Dissolve(c.Blackness(n + 1), c, n)
Dissolve(c, c.Blackness(n + 1), n)respectively.

Therefore, instead of using FadeIn/FadeOut, perhaps you should use:
Dissolve(c.Blackness(n), c, n - 1)
Dissolve(c, c.Blackness(n), n - 1)And then you won't have the additional frames.

Swan
19th August 2003, 16:06
Stickboy, thanks for the suggestion.
I don't mind the extra frame that fadein/fadeout adds.
And I'm not very skilled with Avisynth, so "dissolve" looks intimidating. ;)

stickboy
19th August 2003, 18:40
Originally posted by Swan
Stickboy, thanks for the suggestion.
I don't mind the extra frame that fadein/fadeout adds.But without the extra frames, you can use AudioDub afterward without adjusting the timing. Isn't that what you wanted?
And I'm not very skilled with Avisynth, so "dissolve" looks intimidating. ;)Hm? Just do what I said, or make functions out of them:
function MyFadeIn(clip c, int n)
{
return Dissolve(c.Blackness(n), c, n - 1)
}

function MyFadeOut(clip c, int n)
{
return Dissolve(c, c.Blackness(n), n - 1)
}There shouldn't be anything intimidating about that...

Swan
19th August 2003, 20:11
But without the extra frames, you can use AudioDub afterward without adjusting the timing. Isn't that what you wanted?
Not necessarily. But your suggestion is interesting too.
I wanted help with modifying the old fade-video-only-script I was using (with the command "delayaudio" in it) so that audio and video is dubbed together before the fades (so I won't need "delayaudio").
I am not skilled enough to understand why Wilbert's suggestion also fades the audio. But it does.

Can you give me an example on how I would use:?
function MyFadeIn(clip c, int n)
{
return Dissolve(c.Blackness(n), c, n - 1)
}

function MyFadeOut(clip c, int n)
{
return Dissolve(c, c.Blackness(n), n - 1)
}
I want to fade 25 frames at the start and 50 at the end.
How would I do it?

stickboy
19th August 2003, 21:11
Wilbert's suggestion fades the audio because it dubs the audio before calling FadeIn/FadeOut, and FadeIn/FadeOut fade the audio.

The point of getting rid of the extra frames is so that you can use AudioDub to dub the original audio track back in without needing to use DelayAudio.

Therefore, if you start with separate video and audio sources, you can use:video = AVISource("test.avi")
audio = WAVSource("test.wav")
video = MyFadeIn(video, 25)
video = MyFadeOut(video, 50)
video = AudioDub(video, audio)If you're getting your video and audio from the same AVI source, then you could use:
sourceClip = AVISource("test.avi")
newVideo = MyFadeIn(sourceClip, 25)
newVideo = MyFadeOut(newVideo, 50)
AudioDub(newVideo, sourceClip)

Swan
20th August 2003, 20:57
Stickboy, thanks for all your help.

Am I doing something wrong or is this script correct?

function MyFadeIn(clip c, int n)
{
return Dissolve(c.Blackness(n), c, n - 1)
}

function MyFadeOut(clip c, int n)
{
return Dissolve(c, c.Blackness(n), n - 1)
}
video = AVISource("test.avi")
audio = WAVSource("test.wav")
video = MyFadeIn(video, 25)
video = MyFadeOut(video, 50)
video = AudioDub(video, audio)

Problem #1: I get "'Avisynth Open Failure: the script's return value was not a video clip'" when I try to open it in VirtualDub.
I ask if my script is OK because I have to add the word "video" at the very end to make the script open in VirtualDub. Why is that?

Problem#2: The test.avi file has 1700 frames. When opening it via the script above, it has 1702 frames. So, it seems your function adds 2 frames too...?

stickboy
21st August 2003, 05:39
Originally posted by Swan
Problem #1: I get "'Avisynth Open Failure: the script's return value was not a video clip'" when I try to open it in VirtualDub.
I ask if my script is OK because I have to add the word "video" at the very end to make the script open in VirtualDub. Why is that?A script needs to provide a video clip. Suppose you had the following script:clip1 = AVISource("foo.avi")
clip2 = AVISource("bar.avi")If you tried to open it, how would Avisynth know whether to output clip1 or clip2? It doesn't. Every script has to "return" a clip to specify what to output, like this:clip1 = AVISource("foo.avi")
clip2 = AVISource("bar.avi")
return clip2Now, if you don't have an explicit return statement at the end, Avisynth automatically assumes it's:clip1 = AVISource("foo.avi")
clip2 = AVISource("bar.avi")
return lastThe problem here is: what's last? last is the clip last produced that hasn't been assigned to a variable already. Hence, in this case, last isn't anything, and you get an error.

Now, if you have:clip1 = AVISource("foo.avi")
clip2 = AVISource("bar.avi")
clip2In this case, last is set to that bare clip2 statement at the end, which becomes the final output.
Problem#2: The test.avi file has 1700 frames. When opening it via the script above, it has 1702 frames. So, it seems your function adds 2 frames too...? [/B]Oops. I should have checked it first. Sorry, try this instead:
function MyFadeIn(clip c, int n)
{
# remove the first frame from c
c = c.Trim(1, 0)
return Dissolve(c.Blackness(n), c, n - 1)
}

function MyFadeOut(clip c, int n)
{
# remove the last frame from c
c = c.Trim(0, -(c.Framecount() - 1))
return Dissolve(c, c.Blackness(n), n - 1)
}

Swan
21st August 2003, 10:45
Stickboy, with the script below, I get this error message:

"Avisynth Open failure: Script error: end of file reached without matching" then the path to test.avi and "line 19 column 0"

function MyFadeIn(clip c, int n)
{
# remove the first frame from c
c = c.Trim(1, 0)
return Dissolve(c.Blackness(n), c, n - 1)
}

function MyFadeOut(clip c, int n)
{
# remove the last frame from c
c = c.Trim(0, -(c.Framecount() - 1))
return Dissolve(c, c.Blackness(n), n - 1)
video = AVISource("test.avi")
audio = WAVSource("test.wav")
video = MyFadeIn(video, 25)
video = MyFadeOut(video, 50)
video = AudioDub(video, audio)

Bidoche
21st August 2003, 10:53
You missed the ending } of the definition of MyFadeOut.