Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd August 2017, 11:22   #1001  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,154
Quote:
Originally Posted by JoeSuper8 View Post
Also how should I add the GamMac script to VideoFredís script? I am not sure how to use the FredAverage and without it, using VideoFred and GamMacís script is resulting in noticeable color banding as mentioned elsewhere.
I'll try implement dithering.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but are any of them infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 24th August 2017, 05:34   #1002  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,251
A script like this (with many chained filters) would be an ideal candidate for porting to AVS+ at 10-bits or greater. I might be able to help, using whatever knowledge I picked up doing the (unfinished) documentation.
raffriff42 is offline   Reply With Quote
Old 13th September 2017, 23:34   #1003  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
I finally got around to adding GamMac to my version of VideoFred's script. I also got around to doing a lot of deferred housecleaning. As one example, I never use any of the manual controls because I do all those corrections in my NLE. So, I took them out.

I started to think about the order of the restoration steps and decided I could get a better result if I did degraining first, and then used the motion-compensated version of RemovedDirt second. This seems to produce a more pleasing result because with RemoveDirt first, I was getting too much correlation in the remaining grain, i.e., the image movement sometimes looked "gooey" as things moved around.

GamMac introduces a lot of flicker and I wasn't able to find any settings that would eliminate that. So, I moved Deflicker to the end of the restoration chain and, fortunately, it removes the flicker that GamMac introduces, as well as most flicker in the film itself. Hopefully I'll be able to get a better handle on GamMac over the coming weeks and perhaps eliminate that problem.

I thought about posting this in the thread that branched out from this one. That is where I posted my previous update. However, that thread has gone dormant, while this one is still active, so I'm posting here.

I am also including the "filldrops()" function. I find this incredibly useful. In my NLE (Vegas) I wrote a script that lets me, with the push of one button, replace any bad frame with a copy of the previous frame. This is useful for burned frames; huge dirt spots; bad registration errors during transfer (e.g., a frame that "jumps"); a photographer's flash; and anything else that is distracting or annoying that only lasts for one single frame. Since each duplicate frame I create in Vegas is a 100% perfect duplicate, it is simple for AVISynth to detect that dup, and it is easy to create a new frame by motion estimating from the surrounding frames. Any frame that is not a duplicate is passed through (which is 99.99% of all frames) so the function has almost no speed penalty because most frames are not altered. Therefore, most of the new interpolated frames are absolutely perfect and cannot be detected. Quite magic, actually.

So, I've put the script into the next two posts. Hopefully people will find it to be a slight improvement over what I've posted in the past.

Last edited by johnmeyer; 13th September 2017 at 23:37. Reason: I hit "save" instead of "preview"
johnmeyer is offline   Reply With Quote
Old 13th September 2017, 23:38   #1004  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
Code:
# Film restoration script by videoFred.
# Denoising, resizing, stabilising, sharpening, auto-levels and auto-white balance.
#
# Modified by John Meyer, October 7, 2012
# Modified by John Meyer, July 7, 2015 (remove errors)
# Modified by John Meyer, September 13, 2017
#
# Changes made by Meyer (June 8, 2010):
#   1. Replaced the MVDegrainMulti function, which was part of the original MVTools
#      with the equivalent function using the newer and faster MVTools2.
#   2. Added RemoveDirt function prior to Degrain in order to eliminate large dust spots. This
#      substantially improves the dirt removal capabilities of this script. The user will need to 
#      download this plugin at:
#          http://www.removedirt.de.tf/
#   3. Eliminated a great deal of sharpening. The original script did sharpening in at least four places.
#      With grainy film stock, this sometimes created objectionable grain. Also, the limitedSharpenFaster
#      function, while excellent for video, is uncessarily slow, and isn't really needed for this low 
#      resolution source. Too much sharpening can make the film look too much like video.
#   4. Added multithreading. I was able to roughly triple the script performance. It may be possible to
#      substantially increase this, perhaps as much as 12x instead of 3x. However, the autolevels function
#      would have to be replaced.
#   5. Fixed several things I found. The result3 option didn't have the manual color correction code, so I 
#      added that back in. All the numbered "stab" variables (stab1, stab2, etc.) aren't needed except 
#      for providing a test function for stabilization. I eliminated all of this to streamline the script.
#   6. Deflicker seemed redundant, given all the averaging that takes place with MDegrain, and also the averaging
#      that is done when the autolevels outputs are selected. 
#   7. I reduced the number of frames used for averaging autolevels from the default (which is 5) to 2.
#      I probably should add a variable in the header so the user can change this. Something else to do
#      in the future ...
#   8. I added yet another set of crop parameters. I did this because both my capture and my output are 
#      done using NTSC DV AVI which is 720x480. However, 8mm film is almost exactly square, so the captured
#      720x480 video has black bars on the side. These need to be cropped off prior to doing motion 
#      stabilization, but then added back prior to the final output, which must still be 720x480 with the
#      black bars on the side.
#   9. I reduced the default depan settings to 20, which is what was recommended in the original script. I
#      also reduced the post-depan cropping. I did this so I could keep as much of the original frame
#      as possible.
#  10. I removed the second denoising and sharpening function. It just seemed to be too much, and made the 
#      result too artificial
#  11. I removed the MVFLowFPS interpolation. I did this during one of dozens and dozens of attempts
#      to improve the speed of the script. I should probably add this back, but if I do so, I also 
#      need to make it work correctly for interlaced output. If the goal is to show this on an NTSC or PAL
#      television set, then it is not correct to convert from the film fps to 25 fps progressive (PAL) or
#      29.97 fps progressive (NTSC). Instead, this should be done as follows (example given is NTSC):
#
#         MFlowFPS(source,super,backward_vec, forward_vec, num=60000, den=1001,ml=200)
#         SeparateFields()
#         SelectEvery(4, 0, 3)
#         Weave()
#
#      This yields interlaced 29.97, which has twice the temporal resolution as 29.97 progressive, and will
#      therefore look correct on a TV set. I have done a lot of this as part of my Kinescope to video
#      conversion scripts. For those scripts, the goal is to make the filmed version of a TV show look
#      like it was actually videotaped. However, for something that originated on film, this "does violence"
#      to the original feel of the media. It is true that it can make horizontal pans less "juddery," but
#      it won't feel like film anymore. Also, this technique does break down, espcially with fast motion
#      in the foreground.
#  12. Removed the unecessary "coloryuv(off_U=blue,off_V=red)" statement from the denoising section.
#  13. Added killaudio() statement to prevent lockups when using SetMTMode().
#
# Changes made on October 7, 2012
#
#   1. Modified RemoveDirtMC function to do estimation in two steps. This improves performance and quality.
#   2. Modified MDegrain to do estimation in two steps. This provides roughly the same quality with blocksize=8
#      as what I was getting with blocksize=4, but with virtually no performance penalty
#   3. Updated to use special build of MVTools2 that works with SVP.
#   4. Moved Autolevels inside special multi-threading section in order to improve performance with autolevels.
#   5. Removed all trim commands because I do all editing outside the script (in Vegas).
#   6. Included two alternative ways to do frame interpolation: SVP and InterFrame. The InterFrame script is probably better
#      but I included the SVP code because it may provide a starting point for more customized approaches. Neither is enabled by default.
#
# Changes made on September 13, 2017
#
#   1. Replaced old useless color correction with GamMac.
#   2. Removed never-used manual controls.
#   3. Moved deflicker to end of chain because GamMac introduces flicker.
#   4. Moved RemoveDirtMC to happen AFTER denoising.
johnmeyer is offline   Reply With Quote
Old 13th September 2017, 23:39   #1005  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
Code:
#====================================================================================

#VIDEO FILE
#----------------------------------------------------------------------------------------------------------------------------
#Change the following line to point to your video file
film="e:\fs.avi"


#GENERAL PARAMETERS
#----------------------------------------------------------------------------------------------------------------------------
result="resultS2"                                 #specify the wanted output here 
play_speed=16                                     #play speed (8mm=16; Super8=18; 16mm sound=24)


#COLOR AND LEVELS PARAMATERS
#----------------------------------------------------------------------------------------------------------------------------
saturation = 1.0                                  #for all outputs
gamma      = 1.0                                  #for all outputs 

#GamMac Parameters
LockChan   = 0                                     #(0=red channel)
Scale      = 1
RedMul     = 1.0
GrnMul     = 1.0
BluMul     = 1.0
LockVal    = 128.0
Th         = 0.1


#SIZE, CROP AND BORDERS PARAMETERS
#----------------------------------------------------------------------------------------------------------------------------
CLeft=8  CTop=8  CRight=8  CBottom=8                             #crop values after Depan and before final resizing 
W=720  H=480                                                     #final size after cropping 
bord_left=0        bord_top=0     bord_right=0     bord_bot=0    #720p= borders 150
in_bord_left=0  in_bord_top=0  in_bord_right=0  in_bord_bot=0    #Borders around input that must be removed


#STABILISING PARAMETERS
#----------------------------------------------------------------------------------------------------------------------------
maxstabH=10                                                      #maximum values for the stabiliser (in pixels) 20 is a good start value 
maxstabV=10
est_left=40  est_top=40  est_right=40  est_bottom=40             #crop and contast values for special Estimate clip
est_cont=1.6


#DENOISING PARAMETERS
#----------------------------------------------------------------------------------------------------------------------------
denoising_strength=600                    #denoising level of first denoiser: MVDegrain() 
block_size=   16                           #block size of MVDegrain
block_size_v= 16
block_over=    8                           #block overlapping of MVDegrainMulti()

#Alternate denoising using smaller block size
#denoising_strength= 600                   #denoising level of first denoiser: MDegrain() 
#block_size=   8                           #block size of MVDegrain
#block_size_v= 8
#block_over=   4                           #block overlapping of MVDegrainMulti()

#Alternate denoising using smalles block size
#denoising_strength= 600                   #denoising level of first denoiser: MDegrain() 
#block_size=   4                           #block size of MVDegrain
#block_size_v= 4
#block_over=   2                           #block overlapping of MVDegrainMulti()

dirt_strength=18                           #sets amount of dirt removal (big spots)


#FOUR STEP SHARPENING PARAMETERS
#--------------------------------------------------------------------------------------------------------------------------------
#120 is pretty aggressive; 85 seems more subtle
#PRE_sharp_ness= 120   PRE_radi_us= 3            #presharpening (UnsharpMask) just after first denoising
 PRE_sharp_ness= 85    PRE_radi_us= 3            #presharpening (UnsharpMask) just after first denoising

Sharp_Strength = 0.1                             #0.05 is often better (avoid too much sharpening)


#AUTO LEVELS PARAMETER
#--------------------------------------------------------------------------------------------------------------------------------
X=4   #X  parameter for reducing the autolevels effect on the whites
X2=4  #X2 parameter for reducing the autolevels effect on the blacks 


#NUMBER OF THREADS
#--------------------------------------------------------------------------------------------------------------------------------
threads=4


# END VARIABLES, BEGIN SCRIPT
#=================================================================================================================================

SetMemoryMax(768)

LoadPlugin ("mvtools2.dll")        #Version 2.5.11.9    2/24/2012
LoadPlugin("autolevels.dll")       #Version 0.6.0.0     1/09/2011
LoadPlugin("Deflicker.dll")        #Version 0.4.0.0     8/16/2004
Loadplugin("Depan.dll")            #Version 1.10.0.0    4/09/2007
LoadPlugin("DepanEstimate.dll")    #Version 1.9.2.0     3/25/2007
LoadPlugin("fft3dfilter.dll")      #Version 2.1.1.0     2/20/2007
Loadplugin("mt_masktools.dll")     #Version 2.0.23.0    3/14/2008
loadplugin("RemoveDirtSSE2.dll")   #Version 0.9         5/05/2005    
Loadplugin("RemoveGrainSSE2.dll")  #Version 0.9         5/01/2005
#Loadplugin("removegrain.dll")     #Version 0.9         5/01/2005
Loadplugin("warpsharp.dll")        #                    4/05/2010

#Use the following for alternative frame interpolation
#loadplugin("svpflow1.dll")        #Version 1.2.1.0     5/29/2012
#loadplugin("svpflow2.dll")        #Version 1.3.1.0     6/02/2012 
#Import("InterFrame2.avsi")        #Version 2.1.0       6/27/2012


#Remove all setmtmode statements (there are three in this script) if not using multi-threaded (MT) AVISynth
setmtmode(5,threads)
source1= Avisource(film).killaudio().assumefps(play_speed).converttoYV12()
cropped_source=source1.crop(in_bord_left,in_bord_top,-in_bord_right,-in_bord_bot)               #remove any black borders on input video
setmtmode(2)

#cropped_source=filldrops(cropped_source)     #Use this when removing bad frames that have been removed by duplicating previous frame


#STABILIZING
#....................................................................................................................................................................
stab_reference= cropped_source.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).greyscale().invert()
mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstabH,dymax=maxstabV)
stab=DePanStabilize(cropped_source,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=1,mirror=15)
stabcrop=stab.crop(CLeft,CTop,-CRight,-CBottom)


#DENOISING
#...................................................................................................................................................................
  prefiltered = RemoveGrain(stabcrop,2)
  superfilt =   MSuper(prefiltered, hpad=32, vpad=32,pel=2)
  super=        MSuper(stabcrop, hpad=32, vpad=32,pel=2)

  halfblksize= (block_size>4)   ? block_size/2 : 4
  halfoverlap= (block_over>2)   ? block_over/2 : 2

  bvec1 =  MAnalyse(superfilt, isb = true,  delta = 1, blksize=block_size, overlap=block_over,dct=0)
  bvec1 =  MRecalculate(super, bvec1, blksize=halfblksize, overlap=halfoverlap,thSAD=100) 

  fvec1 =  MAnalyse(super, isb = false, delta = 1, blksize=block_size, overlap=block_over,dct=0)
  fvec1 =  MRecalculate(super, fvec1, blksize=halfblksize, overlap=halfoverlap,thSAD=100)

  bvec2 =  MAnalyse(super, isb = true,  delta = 2, blksize=block_size, overlap=block_over,dct=0)
  bvec2 =  MRecalculate(super, bvec2, blksize=halfblksize, overlap=halfoverlap,thSAD=100)

  fvec2 =  MAnalyse(super, isb = false, delta = 2, blksize=block_size, overlap=block_over,dct=0)
  fvec2 =  MRecalculate(super, fvec2, blksize=halfblksize, overlap=halfoverlap,thSAD=100)

#  Use these additional vectors if you enable three level denoising (below)
#  bvec3 =  MAnalyse(super, isb = true,  delta = 2, blksize=block_size, overlap=block_over,dct=0)
#  bvec3 =  MRecalculate(super, bvec3, blksize=halfblksize, overlap=halfoverlap,thSAD=100)
#  fvec3 =  MAnalyse(super, isb = false, delta = 2, blksize=block_size, overlap=block_over,dct=0)
#  fvec3 =  MRecalculate(super, fvec3, blksize=halfblksize, overlap=halfoverlap,thSAD=100)


#Use the second line below, and un-comment the four lines above if you want to average more frames. Doesn't seem necessary for most work IMHO.
denoised=stabcrop.MDegrain2(super, bvec1,fvec1,bvec2,fvec2,thSAD=denoising_strength).levels(0,gamma,255,0,255).tweak(sat=saturation).unsharpmask(PRE_sharp_ness,PRE_radi_us,0)

#Three level denoising
#denoised=stabcrop.MDegrain3(super, bvec1,fvec1,bvec2,fvec2,bvec3,fvec3,thSAD=denoising_strength).tweak(sat=saturation).unsharpmask(PRE_sharp_ness,PRE_radi_us,0)

#Remove Dirt
denoised = RemoveDirtMC(denoised,dirt_strength,false)

#SHARPENING
#...................................................................................................................................................................
sharp1=denoised.sharpen(Sharp_Strength)	

PreBorderFrame = sharp1.Lanczos4Resize(W - bord_left - in_bord_left - bord_right - in_bord_right, H - bord_top - in_bord_top - bord_bot - in_bord_bot)

#FRAME INTERPOLATION (optional)
#...................................................................................................................................................................
#Everything in this section is commented out because I usually choose NOT to do frame interpolation because 
#it causes too many unexpected artifacts on certain frames. It also makes the film look like video which
#aesthetically is not always pleasing.

/*
prefiltered = RemoveGrain(PreBorderFrame,2)
super = MSuper(PreBorderFrame,hpad=16, vpad=16, levels=1) # one level is enough for MRecalculate
superfilt = MSuper(prefiltered, hpad=16, vpad=16) # all levels for MAnalyse
backward = MAnalyse(superfilt, isb = true, blksize=16,overlap=8,search=3,dct=0)
forward = MAnalyse(superfilt, isb = false, blksize=16,overlap=8,search=3,dct=0)
forward_re = MRecalculate(super, forward, blksize=8, thSAD=100)
backward_re = MRecalculate(super, backward, blksize=8, thSAD=100)
PreBorderFrame = MFlowFps(PreBorderFrame,super, backward_re, forward_re, num=30000, den=1001,ml=200,mask=2)
*/

#Alternative interpolation
/*
superfps= MSuper(PreBorderFrame,pel=2)
backward_vec2 = MAnalyse(superfps, isb = true,blksize=16)
forward_vec2  = MAnalyse(superfps, isb = false,blksize=16)
PreBorderFrame = MFlowFps(PreBorderFrame,superfps, backward_vec2, forward_vec2, num=60000, den=1001, ml=200).SeparateFields().SelectEvery(4, 0, 3).Weave()
*/

#Yet another way to do interpolation
#The following alternative can provide synthesized frames for hi-def material that causes MSuper to choke
#////// Begin alternative to MFlowFPS ////
#SmoothFPS2(PreBorderFrame,threads)
#////// End alternative to MFlowFPS ////

#A final way to do interpolation, although Interframe is just a front-end to SmoothFPS, so I don't think the results are any different.
#The following is another alternative that can provide synthesized frames for hi-def material that causes MSuper to choke. Probably better than the one above.
#////// Begin alternative to MFlowFPS ////
#PreBorderFrame=InterFrame(NewNum=30000,NewDen=1001,PreBorderFrame,GPU=true,Cores=threads)
#////// End alternative to MFlowFPS ////

#RESULT1: AUTOLEVELS,AUTOWHITE
#......................................................................................................................................................................
result1= PreBorderFrame.ConvertToRGB24.GamMac(Show=False, LockChan=LockChan, Th=Th, LockVal=LockVal, Scale=Scale, RedMul=RedMul, GrnMul=GrnMul, BluMul=BluMul).converttoYV12().deflicker().addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000).autolevels(filterRadius=2).crop(X,0,-X2,-0).addborders(bord_left+in_bord_left, bord_top+in_bord_top, bord_right+in_bord_right, bord_bot+in_bord_bot)

#RESULT2: AUTOWHITE
#......................................................................................................................................................................
result2= PreBorderFrame.ConvertToRGB24.GamMac(Show=False, LockChan=LockChan, Th=Th, LockVal=LockVal, Scale=Scale, RedMul=RedMul, GrnMul=GrnMul, BluMul=BluMul).converttoYV12().deflicker().addborders(bord_left+in_bord_left, bord_top+in_bord_top, bord_right+in_bord_right, bord_bot+in_bord_bot)

#RESULT3: AUTOLEVELS
#.....................................................................................................................................................................
result3= PreBorderFrame.addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000).autolevels(filterRadius=2).crop(X,0,-X2,-0).addborders(bord_left+in_bord_left, bord_top+in_bord_top, bord_right+in_bord_right, bord_bot+in_bord_bot)

#RESULT4: NO CORRECTIONS
#.....................................................................................................................................................................
result4= PreBorderFrame.addborders(bord_left+in_bord_left, bord_top+in_bord_top, bord_right+in_bord_right, bord_bot+in_bord_bot)

#PARAMETERS FOR THE COMPARISONS
#.....................................................................................................................................................................
W2= W+bord_left+bord_right
H2= H+bord_top+bord_bot
source4=Lanczos4Resize(source1,W2,H2)


#COMPARISONS: ORIGINAL VS RESULTS
#......................................................................................................................................................................
resultS1= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result1,"autolevels, autowhite",size=28,align=2))
resultS2= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result2,"autowhite",size=28,align=2))
resultS3= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result3,"autolevels",size=28,align=2))
resultS4= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result4,"no level or color corrections",size=28,align=2))

Eval(result)


# END SCRIPT, BEGIN FUNCTIONS
johnmeyer is offline   Reply With Quote
Old 13th September 2017, 23:39   #1006  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
Code:
#=================================================================================================================================


#REMOVE DIRT FUNCTION
#......................................................................................................................................................................
function RemoveDirt(clip input, int "limit", bool "_grey")
{
  clensed=input.Clense(grey=_grey, cache=4)
  alt=input.RemoveGrain(2)
  return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=6,cthreshold=8, gmthreshold=40,dist=3,dmode=2,debug=false,noise=limit,noisy=4, grey=_grey)

  # Alternative settings
  # return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=4,cthreshold=6, gmthreshold=40,dist=1,dmode=2,debug=false,noise=limit,noisy=12,grey=_grey,show=true)
  # return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=6,cthreshold=8, gmthreshold=40,dist=3,tolerance= 12,dmode=2,debug=false,noise=limit,noisy=12,grey=_grey,show=false)
}

function RemoveDirtMC(clip,int "limit", bool "_grey")
{
  _grey=default(_grey, false)
  limit = default(limit,6)

# Alternative way to do pre-filtering.
#  prefiltered = fft3dfilter(clip,sigma=1,sigma2=2,sigma3=3,sigma4=5,bw=64,bh=64)
  
  prefiltered = RemoveGrain(clip,2)
  superfilt = MSuper(prefiltered, hpad=32, vpad=32,pel=2)

  super=MSuper(clip, hpad=32, vpad=32,pel=2)

  bvec = MAnalyse(superfilt,isb=true,  blksize=16, overlap=2,delta=1, truemotion=true)
  fvec = MAnalyse(superfilt,isb=false, blksize=16, overlap=2,delta=1, truemotion=true)

# Increase thSAD if moving objects are being removed
  bvec_re = Mrecalculate(super,bvec,blksize=8, overlap=0,thSAD=100)
  fvec_re = Mrecalculate(super,fvec,blksize=8, overlap=0,thSAD=100)

  backw = MFlow(clip,super,bvec_re)
  forw  = MFlow(clip,super,fvec_re)

  clp=interleave(forw,clip,backw)
  clp=clp.RemoveDirt(limit,_grey)
  clp=clp.SelectEvery(3,1)
  return clp
}

#This function is the previous way to do motion estimation. It is slower and not as accurate.
function RemoveDirtMC_old(clip,int limit, bool "_grey")
{
  _grey=default(_grey, false)
  limit = default(limit,6)
  i=MSuper(clip,pel=2)
  fvec = MAnalyse(i,isb=false, blksize=16, delta=1, truemotion=true)
  bvec = MAnalyse(i,isb=true,  blksize=16, delta=1, truemotion=true)
  backw = MFlow(clip,i,bvec)
  forw  = MFlow(clip,i,fvec)
  clp=interleave(forw,clip,backw)
  clp=clp.RemoveDirt(limit,_grey)
  clp=clp.SelectEvery(3,1)
  return clp
}

# This function will remove near duplicates ("0.1") or exact duplicates (change to "0.0"). It replaces these
# duplicates with a motion estimated frame. 
# Use: In your video editor, replace any single bad frame (burned frame, jump, missing frame from splice, etc.) with a duplicate of the 
# previous frame. Then, include a call to this function

function filldrops (clip c)
{
  super=MSuper(c,pel=2)
  vfe=manalyse(super,truemotion=true,isb=false,delta=1)
  vbe=manalyse(super,truemotion=true,isb=true,delta=1)
  filldrops = mflowinter(c,super,vbe,vfe,time=50)
  fixed = ConditionalFilter(c, filldrops, c, "YDifferenceFromPrevious()", "lessthan", "0.1")
  return fixed
}


function SmoothFPS2(clip source, threads) { 
  super_params="{pel:2,gpu:1}"
  analyse_params="""{
        block:{w:16,h:16}, 
	main:{search:{coarse:{distance:-10}}},
	refine:[{thsad:200}]
        }"""
  smoothfps_params="{rate:{num:30,den:16,abs:false},scene:{mode:0,limits:{scene:8500}},algo:21,cubic:1}"
  threads = 4

  super =   SVSuper(source,super_params)
  vectors = SVAnalyse(super, analyse_params)
  SVSmoothFps(source,super,  vectors,  smoothfps_params,  url="www.svp-team.com",  mt=threads)

# Alternative for interlaced output
# SVSmoothFps(source,super, vectors, smoothfps_params, url="www.svp-team.com", mt=threads).SeparateFields().SelectEvery(4, 0, 3).Weave().assumefps(29.97)
}
johnmeyer is offline   Reply With Quote
Old 14th September 2017, 01:03   #1007  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,154
John, scale = 2 (EDIT with Th=0) , in GamMac WILL see all pixels (even a single) as affecting min/max, avoid noise pixels by eg denoise on DC clip,
with a perfect source that may be what you want, with less than prefect, needs more effort.

@ Lem, GamMac never was intended to be any kind of one suit fits all, merely a pre tweak easy get in sync type of thing.
If we all had Lem at our sides, GamMac would be of little worth.
John, seek Lem's counsil, he seems to be the man
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but are any of them infinitely bigger ???

Last edited by StainlessS; 14th September 2017 at 01:07.
StainlessS is offline   Reply With Quote
Old 14th September 2017, 23:08   #1008  |  Link
bassquake
Registered User
 
Join Date: Jan 2007
Posts: 10
I have a question regarding settings frame rate, as I did a quick search through this thread but couldnt find the info.

I've built a telecine to capture standard 8 and super 8 into separate images. I assume they were shot at 18fps and would like to create 24fps videos (true 24p). The comments in the script file confuses me when it mention 18.75fps. So do I set it like so (need to change denumerator?):

play_speed= 18.75
numerator= 24
denumerator= 1

or

play_speed= 18
numerator= 24
denumerator= 1

Help appreciated, thanks.
bassquake is offline   Reply With Quote
Old 15th September 2017, 03:32   #1009  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
"Play speed" is the speed that you think the original was played (e.g., 18 fps for Super 8).

I recommend doing standard pulldown rather than any sort of motion estimation. Despite heroic efforts to improve motion estimation, it fails way too many times and will give you a mountain of weird-looking frames. I am in the process now of doing four separate restorations of the same material. Two of the 2x2 matrix variations involve using, or not using GamMac, because it fails to do the right thing quite often. The other two variations involve generating an alternate to motion estimation which I used, not to change frame rate, but to fix hundreds of screwed-up frames. In 90% of the cases, the fix was near-perfect but, as is always true with ME, when it fails, it fails spectacularly and calls attention to itself. So, I am doing another set of GamMac and no GamMac with an alternative to ME that doesn't look as good, but never fails.

You can adapt this code to create pulldown for whatever you are doing:

Code:
#18p -> 60i

avisource("video.avi")
assumefps(18)
changefps(59.94)
separatefields()
selectevery(4,0,3)   #depends on wished field-order
#selectevery(4,1,2)  #alternate field order
weave()
johnmeyer is offline   Reply With Quote
Old 15th September 2017, 07:56   #1010  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,098
Quote:
Originally Posted by bassquake View Post
...and would like to create 24fps videos (true 24p).
Mind if I ask 'why'? Is it for DVD perhaps? Offhand I can't think of any other reason it has to be 24fps.
manono is offline   Reply With Quote
Old 15th September 2017, 08:33   #1011  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
After seeing manono's comment, I re-read his post, and he emphasized "true" 24p. I guess I need clarification of what that means. Forgetting for a moment about the 23.976 vs. 24.000 thing, if he really wants 24 unique frames each second, then motion interpolation is the only choice. That is built into both VideoFred's script, and in my adaptation of his script. I don't recommend it, however, because even if you use the masked version of Interframe that was recently developed, you'll still end up with a LOT of bad frames. The lower the frame rate (and 16 or 18 fps is pretty low), the bigger the temporal gap between frames, and the larger and more frequent these errors become. Motion estimation works really well on 60p material (for when you want to get super-slo-mo) because it doesn't have to move the pixels very far to make the tween frames, but it doesn't work that well on amateur silent film. I've posted the link to my Flint, MI parade many times which I converted from 16 to 30p before I uploaded, and it is a textbook case of what can go wrong.

So, if you want true 24p, ME is the only tool that I know of that will give you what you want, and the code is already posted in this thread.
johnmeyer is offline   Reply With Quote
Old 15th September 2017, 11:17   #1012  |  Link
bassquake
Registered User
 
Join Date: Jan 2007
Posts: 10
I want to output to bluray but I suppose I can use 23.976 if that's easier?

So would the code then be?:

play_speed= 18.75
numerator= 23.976
denumerator= 1001

Thanks for responses so far.
bassquake is offline   Reply With Quote
Old 15th September 2017, 23:05   #1013  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
Quote:
Originally Posted by bassquake View Post
I want to output to bluray but I suppose I can use 23.976 if that's easier?

So would the code then be?:

play_speed= 18.75
numerator= 23.976
denumerator= 1001

Thanks for responses so far.
No, that is wrong. 23.976 = 24.000 / 1001.0 (make sure to use the decimal to force float)

But, as I said in my previous post, that is a relatively minor issue compared to the bigger point I was trying to make, and which I won't repeat again here.

[edit]Groucho2004 points out my error (a few posts below this one). I put the decimal in wrong place. I was only off by a factor of 1,000.
The correct equations are: 24.000 / 1.001 or 24000.0 / 1001.0

Last edited by johnmeyer; 16th September 2017 at 23:02. Reason: post correct equation
johnmeyer is offline   Reply With Quote
Old 16th September 2017, 02:42   #1014  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,154
John dont overlook the DC clip, even a simple Blur() can avoid some of the flickering effect (so long as only spurious odd pixels are cause of flicker, shimmering water though would probably not benefit).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but are any of them infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 16th September 2017, 04:32   #1015  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,098
Yes, interpolation to go from 18->24fps, but if that doesn't work out so well for the reasons johnmeyer outlined, there is another way that creates blended frames to fill in the gaps. The Motion.dll, can do this to, for example, create 6 new frames every second (a new one after every 3) to go from 18->24fps. Each new frame will be a blend of the ones before and after. Ordinarily I don't like creating blended frames on purpose since I spend my life unblending frames but it might do here.

The reason for my question earlier was, if making a DVD is okay, you only have to bring the framerate up to 19.98fps and you can apply 3:3 pulldown afterwards to output the required 29.97fps. That way you'd have to create only a new frame after every 9, rather than after every 3. Only 10% of the frames would be interpolated. I've never worked with Blu-Ray and have no idea if soft pulldown is allowed.
manono is offline   Reply With Quote
Old 16th September 2017, 21:06   #1016  |  Link
Groucho2004
 
Join Date: Mar 2006
Posts: 3,525
Quote:
Originally Posted by johnmeyer View Post
No, that is wrong. 23.976 = 24.000 / 1001.0 (make sure to use the decimal to force float)
That's also wrong. 23.976 = 24000 / 1001 (or 24000.0 / 1001.0).

ChangeFPS() takes either a float (23.976) or two integers (24000, 1001), see here. In order to avoid rounding errors it's recommended to use the (num, denom) format.

Last edited by Groucho2004; 16th September 2017 at 23:16. Reason: typo
Groucho2004 is offline   Reply With Quote
Old 16th September 2017, 22:59   #1017  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,886
Quote:
Originally Posted by Groucho2004 View Post
That's also wrong. 23.976 = 24000 / 1001 (or 24000.0 / 1001.0).

ChangeFPS() takes either a float (23.976) or two integers (24000, 1001), see here. In order to avoid rounding errors it's recommended to use the (num, denum) format.
Oops. You got me! That'll teach me to post too quickly. I forgot a decimal point.
johnmeyer is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 14:19.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.