Hello guest, if you like this forum, why don't you register? https://fanrestore.com/member.php?action=register (December 14, 2021) x


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AviSynth DeFade function
#1
Code:
###########################################################################################
### DeFade: recovers the faded part of a clip                                           ###
###                                                                                     ###
### Usage: DeFadeIn(clip,frames) and DeFadeOut(clip,frames)                             ###
###                                                                                     ###
### The frames number includes the most near to the unfaded, and the nearest to black   ###
### Nearest black frame(s) suffers of banding                                           ###
###                                                                                     ###
### AviSynth script made by Gavino, using Motenai Yoda's method - Created: 2016-12-29   ###
### Original idea: spoRv - reference: http://forum.doom9.org/showthread.php?t=174140    ###
###                                                                                     ###
### Creative Commons 4,0 - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)      ###
### Link to the licence page: https://creativecommons.org/licenses/by-sa/4.0/           ###
###########################################################################################

function DefadeOut(clip c, int frames) {
 c
 Animate(framecount-frames-1, framecount, "Defade2", 1.0, 0.0)
}

function DefadeIn(clip c, int frames) {
 c.reverse
 Animate(framecount-frames-1, framecount, "Defade2", 1.0, 0.0)
 reverse
}

# Helper function to be animated by Defade()
function Defade2(clip c, float div) {
 mx = 1.0/div
 c.mt_lut(expr="x 128 - "+string(mx)+" * 128 +", yexpr="x 16 - "+string(mx)+" * 16 +",u=3,v=3)
}

To be perfect, if should include also the frame number where the defade should start; but I'm too lazy to do that, so it's up to you - waiting for your modifications!

Happy New Year!
Reply
Thanks given by:
#2
Code:
###########################################################################################
### DeFade 1.1: recovers the faded part of a clip                                       ###
###                                                                                     ###
### Usage: DeFadeIn (clip,frames,bad,start)  and  DeFadeOut (clip,frames,bad,start)     ###
###        DeFadeInX(clip,frames,bad,start)  and  DeFadeOutX(clip,frames,bad,start)     ###
###                                                                                     ###
### The frames number includes the most near to the unfaded, and the nearest to black   ###
### Because sometimes nearest black frame(s) suffers of banding, it's possible to       ###
### replace the last bad frames with the previous good frame; start is the first frame  ###
### of the fade - fadein = first near black, fadeout = first near normal                ###
### DeFadeInX and DeFadeOutX are used when fade is not linear                           ###
###                                                                                     ###
### AviSynth script made by Gavino, using Motenai Yoda's method - Created:  2016-12-29  ###
### Original idea and modification: spoRv                       - Modified: 2017-01-05  ###
### reference: http://forum.doom9.org/showthread.php?t=174140                           ###
###                                                                                     ###
### Creative Commons 4,0 - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)      ###
### Link to the licence page: https://creativecommons.org/licenses/by-sa/4.0/           ###
###########################################################################################

function DeFadeIn(clip clip, int frames, int "cut", int "start") {
 start=default(start,2)
 cut=default(cut,0)
 clip.trim(start,start+frames).reverse
 Animate(framecount-frames-1, framecount, "DeFade2", 1.0, 0.0)
 def=reverse.loop(cut+1,cut,cut).trim(cut,frames+1)
 clip.trim(0,start-1)+def+clip.trim(start+frames,0)
}

function DeFadeOut(clip clip, int frames, int "cut", int "start") {
 start=default(start,2)
 cut=default(cut,0)
 clip.trim(start,start+frames)
 tmp=Animate(framecount-frames-1, framecount, "DeFade2", 1.0, 0.0)
 def=tmp.trim(0,frames-cut-1)+tmp.trim(frames-cut-1,frames-cut-1).loop(cut)
 clip.trim(0,start-1)+def+clip.trim(start+frames,0)
}

function DeFadeInX(clip clip, int frames, int "cut", int "start") {
 start=default(start,2)
 cut=default(cut,1)
 clip.trim(start,start+frames).reverse
 a=Animate(framecount-frames-1, framecount, "DeFade2",  1.0, 0.0)
 b=Animate(framecount-frames-1, framecount, "DeFade2X", 1.0, 0.0)
 def=merge(a,b).reverse.loop(cut+1,cut,cut).trim(cut,frames+1)
 clip.trim(0,start-1)+def+clip.trim(start+frames,0)
}

function DeFadeOutX(clip clip, int frames, int "cut", int "start") {
 start=default(start,2)
 cut=default(cut,1)
 clip.trim(start,start+frames)
 a=Animate(framecount-frames-2, framecount-1, "DeFade2",  1.0, 0.0)
 b=Animate(framecount-frames-2, framecount-1, "DeFade2X", 1.0, 0.0)
 tmp=merge(a,b)
 def=tmp.trim(0,frames-cut-1)+tmp.trim(frames-cut-1,frames-cut-1).loop(cut)
 clip.trim(0,start-1)+def+clip.trim(start+frames,0)
}

# Helper functions to be animated by DeFade()
function DeFade2 (clip c, float div) {
 mx = 1.0/div
 c.mt_lut(expr="x 128 - "+string(mx)+" * 128 +", yexpr="x 16 - "+string(mx)+" * 16 +",u=3,v=3)
}

function DeFade2X(clip c, float div) {
 mx = 1.0/div/div
 c.mt_lut(expr="x 128 - "+string(mx)+" * 128 +", yexpr="x 16 - "+string(mx)+" * 16 +",u=3,v=3)
}
Reply
Thanks given by:
#3
Haven't tried it yet, but this is an interesting idea. What would be some "real-world" applications of this for us here in the community?
Reply
Thanks given by:
#4
Useful to restore some faded frames mainly from trailers/teasers, but sometimes also from deleted scenes.

I must admit the restored frames could be just few - usually less than a dozen for each given fade - but you know, we try to save even one single frame if possible, so...

I used it to restore some frames of the "Bail Organa" (aka Bail Antilles) EP1 deleted scene; I'm planning to use it for SW EEE to get more frames from the trailers and teasers.
Reply
Thanks given by:
#5
Got it. That makes sense, especially the part about trailers/teasers/deleted scenes...
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
  AviSynth GrainPlate function spoRv 8 5,943 2023-07-18, 10:08 PM
Last Post: Bilbofett

Forum Jump:


Users browsing this thread: 1 Guest(s)