With avisynth, I can edit the audio on videos so that it fades in (from zero) or out (to zero). What I'd like to know is: is there an avisynth function/script that allows fading to a certain level eg the start of a video might be at amplification factor 2 with a five second fade down to the original volume?
Thanks.
+ Reply to Thread
Results 1 to 15 of 15
Thread
-
-
see if this thread will help - https://forum.videohelp.com/threads/383792-Using-avisynth-to-fade-out-the-audio
-
If you want to fade up/down from a 2x volume to a 1x volume, etc, and easy cheat is to just use an extra copy of the clip and do the fade only on the copy and combine both clips.
Scott -
Try this:
Code:############################################################### # # Fade audio from 2x to 1x over the specified number of frames. # ############################################################### function FadeFrom2xTo1x(clip source, int NumFrames) { source = source.Amplify(2.0) Trim(source, 0, NumFrames) FadeOut0(NumFrames) Mixaudio(source, last) } ###############################################################
A call like FadeFrom2xto1x(50) will fade audio from 2x to 1x over 50 frames.
VirtualDub's audio waveform of a constant amplitude sine wave after FadeFrom2xto1x(50):
[Attachment 69897 - Click to enlarge]
It would be useful to include the amplification amount as a variable too.Last edited by jagabo; 21st Mar 2023 at 10:02. Reason: added image and note
-
My thanks, guys.
jagabo, special thanks to you. At first, I couldn't see that your function was working so I ended up downloading a clip from youtube of a road drill being used (constant, even sound) and edited it with "trim(200,1000).FadeFrom2xto1x(400)". I could see that it had worked via WavePad (similar to Audacity). Great stuff, thanks again.
I don't fully understand how the function works - I can see where you specify the starting volume but I don't see the closing volume being set. Presumably avisynth just fades to source volume in the absence of being told anything else. Which leads me to this: Say I wanted to make this edit:
Code:Trim(1000,5000).amplify(6)++trim(5001,6000)#reducing volume#++trim(6001,9000).amplify(2)
-
MixAudio() does (A+B)/2 by default. ie the average of two audio clips. I create two streams from the source. One has the volume amplified by 2, A*2. The other has the Volume amplified to A*2 but it fades over 50 frames (or whatever number of frames your specify) to A*0, or 0. So when you mix the two streams you get (A*2 + A*2) / 2 at the start, or A*2, twice the original volume. The volume of the second clip decrease linearly until it reaches A*0 at the end of the clip. So at the end of the short clip you have (A*2 + A*0) / 2, or (A*2) / 2, or just A, the original volume. Since the second clip ends at 50 frames its audio for the rest of that stream is 0. So the the rest of the clip continues to have (A*2 + 0) / 2, or just A -- the original audio volume.
Last edited by jagabo; 21st Mar 2023 at 16:23.
-
Here's a version that lets you specify the initial amplification:
Code:############################################################### # # Fade audio from Nx to 1x over the specified number of frames. # ############################################################### function FadeFromNxTo1x(clip source, int "NumFrames", float "InitialAmplitude") { NumFrames = default(NumFrames, 30) InitialAmplitude = default(InitialAmplitude, 2.0) ampd = source.Amplify((InitialAmplitude-1.0)*2.0) Mixaudio(source.Amplify(2.0), ampd.Trim(0, NumFrames).FadeOut0(NumFrames)) } ###############################################################
-
That's great, many thanks indeed for writing it. I'm guessing that my scenario above (reducing from Amp6 to Amp2) isn't possible as all fades are to Source?
-
-
Clever. 3x2=6. And by stipulating Amplify(2) at the outset, the fade never falls below that?
Many thanks (again). -
Yes.
Here's a more general solution where you specify the initial gain and the final gain. The gain is linearly interpolated over the full clip:
Code:############################################################################# # # Vary audio gain from StartGain to EndGain over the full clip. # ############################################################################# function VariableAmplify(clip Source, float "StartGain", float "EndGain") { NumFrames = Source.FrameCount a1 = Source.Amplify(StartGain*2.0).FadeOut0(Source.FrameCount) a2 = Source.Amplify(EndGain*2.0).FadeIn0(Source.FrameCount) Mixaudio(a1, a2) AudioDub(Source, last) } #############################################################################
Code:Trim(1000,5000).Amplify(6.0)++trim(5001,6000).VariableAmplify(6.0, 2.0)++trim(6001,9000).Amplify(2.0)
-
I've given that script a workout, this time on a 'Tone Test' video and it's certainly an easy script to use. The video I used it on lasts 48 seconds with 1440 frames and this is my script (I changed the name of the function):
Code:function semifade(clip Source, float "StartGain", float "EndGain") { NumFrames = Source.FrameCount a1 = Source.Amplify(StartGain*2.0).FadeOut0(Source.FrameCount) a2 = Source.Amplify(EndGain*2.0).FadeIn0(Source.FrameCount) Mixaudio(a1, a2) AudioDub(Source, last) } LoadPlugin("D:\MeGUI\tools\lsmash\LSMASHSource.dll") a=LSMASHVideoSource("D:\Test Tone.mp4") b=LSMASHaudioSource("D:\Test Tone.mp4") audiodub(a,b) Trim(0,480).Amplify(2)++trim(481,960).semifade(2, 0.5)++trim(961,1440).Amplify(0.5)
Otherwise, terrific script, exactly what I was after.
[Attachment 69918 - Click to enlarge] -
You have blown out the audio. The sections are the correct length but the middle section is maxed out for the first ~1/3 of its duration.
-
You're right. Thanks a lot.
Code:Trim(0,480)++trim(481,960).semifade(1, 0.5)++trim(961,1440).Amplify(0.5)
[Attachment 69919 - Click to enlarge]
Similar Threads
-
Smoothing of dark scene with fading
By VHS_Hunter in forum RestorationReplies: 1Last Post: 3rd May 2020, 04:15 -
Fading JPEGs
By oofers in forum Newbie / General discussionsReplies: 9Last Post: 6th Apr 2019, 21:09 -
JVC HR-S7600EK VHS video fading in and out
By DasHHat in forum MediaReplies: 7Last Post: 1st Jun 2018, 11:13