Log in

View Full Version : Stabilizing image: how?


Dada_
8th December 2008, 22:55
Hey there, I'm working on translating an anime in Dutch. I also want to fix up the image since it's rather poor and from VHS (and even the DVDs are of that poor quality). Here's a short sample clip: http://tmp.thingmajig.org/output.mkv (3,832 KB)

The clip is made with the following script:v = DGDecode_MPEG2Source("c:\avisynth\input_mpg.d2v")
a = DirectShowSource("c:\avisynth\input_mpg Tc0 L2 2ch 44.1 224 DELAY 0ms.mpa")

c = AudioDub(v, a)

c

loadPlugin("C:\Program Files\AviSynth 2.5\plugins\Deen.dll")
deen("a3d",1,10,8)
What I want to do now is stabilize the image. As you can tell from the example I posted, the image has a very subtle shake.

Is it even possible to get this kind of shaking out, or should I just live with it?

I tried using GenMotion:v = DGDecode_MPEG2Source("c:\avisynth\input_mpg.d2v")
a = DirectShowSource("c:\avisynth\input_mpg Tc0 L2 2ch 44.1 224 DELAY 0ms.mpa")

c = AudioDub(v, a)

c

loadPlugin("C:\Program Files\AviSynth 2.5\plugins\avisynth_c.dll")
LoadVirtualdubPlugin("C:\Program Files\AviSynth 2.5\plugins\Deshaker.vdf", "Deshake")
loadCPlugin("C:\avisynth\Genmotion.dll")


converttoYV12(c)
f=GenMotion(c, filename="C:\avisynth\ajkdeshaker.log", delta=1)
b=GenMotion(c, filename="C:\avisynth\ajkdeshaker.log", delta=-1)
interleave(f,c,b)
selectevery(3,1)
converttoYUY2(c)
But it caused the error GenMotion: Cannot open input file ! (C:\avisynth\ajk_shake.avs, line 14)

I don't really know how to fix this. Should I be using this plugin or is there a better one that I could try?

Any help is appreciated! :D

videoFred
9th December 2008, 08:33
Deshaker is a two pass filter! Your script tries to read the deshaker log file. This log file should be created in the first pass from deshaker. I do not know how to configure Avisynth for this, but it should be possible.

Anyhow... Use DepanStabilize() instead. :)

Fred.

PeaceAnt
9th December 2008, 08:56
for first pass i use:
loadvirtualdubplugin("D:\Program Files\VirtualDubMod\plugins\Deshaker.vdf","Deshaker")
Deshaker("11|1|30|4|1.33333|7|1|0|640|480|1|2|1|400|400|400|1500|4|0|1|2|5|40|300|4|"\
+a+".log|0|0|0|0|0|0|0|0|0|0|0|0|0|1|15|15|5|15|0|0|30|30|0|0|0|0|1|0|0|10|1|15|1000|1")
this will analyze motion and save log file.
and then 2nd pass:
loadvirtualdubplugin("D:\Program Files\VirtualDubMod\plugins\Deshaker.vdf","Deshaker")
Deshaker("11|2|30|4|1.33333|7|1|0|640|480|1|2|1|400|400|400|1500|4|1|0|2|5|40|300|4|"\
+a+".log|0|0|0|0|0|0|0|0|0|0|0|0|0|1|2|2|1|1|0|0|30|30|0|0|0|0|1|0|0|10|1|15|1000|1")

deshaker parameters you can copy directly from saved processing settings of virtual dub (*.vcf).

here's result (click "stab unstab.avi"):
http://wyslijplik.pl/download.php?sid=Wt93E7xb


more informations (in polish) on http://forum.filmowiec.pl/viewtopic.php?t=13226

pozdrawiam

Dada_
9th December 2008, 21:57
Thanks, PeaceAnt! I've given it a try, but I can't seem to get (the first pass, at least) to work. It "works" (as in, there's no error) when I view the .avs, but when I try to render it, I get a common fatal error:
avis [error]: unsupported input format (DIB )
x264 [error]: could not open input file 'ajk_pass1.avs'
Here are my scripts.
First pass:
v = DGDecode_MPEG2Source("c:\avisynth\input_mpg.d2v")
a = DirectShowSource("c:\avisynth\input_mpg Tc0 L2 2ch 44.1 224 DELAY 0ms.mpa")

c = AudioDub(v, a)

c

ConvertToRGB32()

log_name = "ajk_shake"

loadPlugin("C:\Program Files\AviSynth 2.5\plugins\avisynth_c.dll")
LoadVirtualdubPlugin("C:\Program Files\AviSynth 2.5\plugins\Deshaker.vdf", "Deshaker")
Deshaker("11|1|30|4|1.33333|7|1|0|640|480|1|2|1|400|400|400|1500|4|0|1|2|5|40|300|4|"+log_name+".log|0|0|0|0|0|0|0|0|0|0|0|0|0|1|15|15|5|15|0|0|30|30|0|0|0|0|1|0|0|10|1|15|1000|1")

Second pass:
v = DGDecode_MPEG2Source("c:\avisynth\input_mpg.d2v")
a = DirectShowSource("c:\avisynth\input_mpg Tc0 L2 2ch 44.1 224 DELAY 0ms.mpa")

c = AudioDub(v, a)

c

ConvertToRGB32()

log_name = "ajk_shake"

loadPlugin("C:\Program Files\AviSynth 2.5\plugins\avisynth_c.dll")
LoadVirtualdubPlugin("C:\Program Files\AviSynth 2.5\plugins\Deshaker.vdf", "Deshaker")
Deshaker("11|2|30|4|1.33333|7|1|0|640|480|1|2|1|400|400|400|1500|4|1|0|2|5|40|300|4|"+log_name+".log|0|0|0|0|0|0|0|0|0|0|0|0|0|1|2|2|1|1|0|0|30|30|0|0|0|0|1|0|0|10|1|15|1000|1")

ConvertToYv12()

loadPlugin("C:\Program Files\AviSynth 2.5\plugins\Deen.dll")
deen("a3d",1,10,8)

loadPlugin("C:\Program Files\AviSynth 2.5\plugins\MaskTools-v1.5.8\MaskTools.dll")
loadPlugin("C:\Program Files\AviSynth 2.5\plugins\MipSmooth.dll")
loadPlugin("C:\Program Files\AviSynth 2.5\plugins\MSharpen.dll")
import("C:\Program Files\AviSynth 2.5\plugins\DeRainbow.avs")
DeRainbow()

To encode the file, I simply do this:
x264.exe ajk_pass1.avs --progress --qp 20 --sar 4:3 --seek 3920 --frames 450 --output output.mkv
x264.exe ajk_pass2.avs --progress --qp 20 --sar 4:3 --seek 3920 --frames 450 --output output.mkv

Do you have any idea why it wouldn't work? Should I change my x264.exe command to have it generate the log?

thetoof
10th December 2008, 06:28
I use this very often to stabilize old anime. It works only for very small shakes that are often present in VHSrips or oldies:
#Original script by g-force
function stab (clip orig, float "pixaspect"){
pixaspect=default(pixaspect,1)
rep=Repair(orig.TemporalSoften(7,255,255,25,2),orig,mode=16).TemporalSoften(1,255,255,25,2)
source=Interleave(rep,orig,rep)
mdata=DePanEstimate(source, range=1, trust=0, dxmax=1, dymax=1)
return DePan(source, data=mdata, offset=1,pixaspect=pixaspect).SelectEvery(3,2)}

You can simply call it as stab() and add a float for the pixel aspect if the filtered clip is anamorphic.

J_Darnley
10th December 2008, 12:49
Do you have any idea why it wouldn't work?
You don't change back to YV12 after using the VDub plugin.

2Bdecided
10th December 2008, 15:36
I don't see the point of sending the first pass of Deshaker to an encoder - just dump it, or send it to a fast lossless file and then delete it.

I've always found it easier to Deshake in virtual dub - to a lossless intermediate file if needs be. I understand why you might want to do it from within AVIsynth, e.g. to go straight to an encoder, but this introduces too many disadvantages for me.

Cheers,
David.

kemuri-_9
10th December 2008, 19:06
I don't see the point of sending the first pass of Deshaker to an encoder - just dump it, or send it to a fast lossless file and then delete it.

virtualdub's 'run video analysis pass' works fairly well.
but then some people just want to stick to cli and not bother with opening up a gui like vdub...

PeaceAnt
10th December 2008, 22:07
i use mencoder with NUL option for first pass...
mencoder.exe %%f -o NUL -ovc frameno -nosound -noskip -mc 0
and to render file
mencoder.exe %%f -o %%~nf.avi -ovc lavc -lavcopts vcodec=mjpeg -oac copy -noskip -mc 0 -ofps 25 -vf crop=1382:1036:29:22,scale=1280:720

pozdrawiam

g-force
10th December 2008, 23:18
here's a newer version of the script that thetoof posted. Give it a shot. You might need to play around with dxmax and dymax.

temp = last.TemporalSoften(7,255,255,25,2)
Interleave(temp.Repair(last.TemporalSoften(1,255,255,25,2)),last)
DePan(last,data=DePanEstimate(last,trust=0,dxmax=10,dymax=10),offset=-1)
SelectEvery(2,0)

-G

McCauley
1st February 2009, 23:12
here's a newer version of the script that thetoof posted. Give it a shot. You might need to play around with dxmax and dymax.

temp = last.TemporalSoften(7,255,255,25,2)
Interleave(temp.Repair(last.TemporalSoften(1,255,255,25,2)),last)
DePan(last,data=DePanEstimate(last,trust=0,dxmax=10,dymax=10),offset=-1)
SelectEvery(2,0)

Added to wiki (http://avisynth.org/mediawiki/Stab).
I converted it into a stand alone script, so you just have to call "stab()"

Thanks g-force!
McCauley

g-force
3rd February 2009, 23:17
Thanks! Nice work!

Jenyok
6th March 2013, 11:48
There is One More Function.
.

##############################################################################
#
# Original script by g-force converted into a stand alone script by McCauley
# latest version from December 10, 2008
#
# http://forum.doom9.org/showthread.php?p=1222830#post1222830
#
##############################################################################

LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\REMOVEGRAIN-1_0\repair.dll")
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\DEPAN_20061128\depan.dll")
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\DEPAN_20061128\depanestimate.dll")



function Stab(clip clp, int "range", int "dxmax", int "dymax", float "trust", float "pixaspect")
{
range = default(range, 1)
dxmax = default(dxmax, 4)
dymax = default(dymax, 3)
trust = default(trust, 0.0)
pixaspect = default(pixaspect, 1.094) # PAL 720x576
# pixaspect = default(pixaspect, 1.0) # PAL 768x576 (640x480)

temp = clp.TemporalSoften(7, 255, 255, 25, 2)
inter = Interleave(temp.Repair(clp.TemporalSoften(1, 255, 255, 25, 2)), clp)
mdata = DePanEstimate(inter, range=range, trust=trust, dxmax=dxmax, dymax=dymax)
DePan(inter, data=mdata, offset=-1, pixaspect=pixaspect)

return (SelectEvery(2, 0))
}



#
#
function Stab2(clip clp, int "range", int "dxmax", int "dymax", float "trust", \
float "pixaspect", float "zoommax", float "rotmax", float "cutoff", \
bool "rot", int "mirror", bool "addzoom")
{
range = default(range, 2)
dxmax = default(dxmax, 4) # 4 : 3
dymax = default(dymax, 3) # 4 : 3
trust = default(trust, 2.0)

pixaspect = default(pixaspect, 1.094) # PAL 720x576
# pixaspect = default(pixaspect, 1.0) # PAL 768x576

zoommax = default(zoommax, 1.05)
rotmax = default(rotmax, 0.5)
cutoff = default(cutoff, 0.1)
rot = default(rot, true)
mirror = default(mirror, 15)
addzoom = default(addzoom, true)

prv = range
nxt = range

# Global Motion Stabilization
# Глобальная стабилизация изображения
#
mdata = DePanEstimate(clp, \
dxmax = dxmax, \
dymax = dymax, \
trust = trust, \
improve = true, \
zoommax = zoommax, \
range = range, \
pixaspect = pixaspect)

# function DePanStabilize(clip, clip data, float cutoff, float damping, bool addzoom, \
# int prev, int next, int mirror, int blur, int dxmax, int dymax, \
# float zoommax, float rotmax, int subpixel, float pixaspect, \
# int fitlast, float tzoom, bool info, string inputlog)
#
return (DepanStabilize(clp, \
data = mdata, \
cutoff = cutoff, \
damping = 0.9, \
initzoom = 1.0, \
addzoom = addzoom, \
prev = prv, \
next = nxt, \
mirror = mirror, \
blur = 50, \
dxmax = dxmax, \
dymax = dymax, \
zoommax = zoommax, \
rotmax = rotmax, \
subpixel = 2, \
pixaspect = pixaspect, \
fitlast = 0, \
tzoom = 3.0, \
info = false))
}

Jenyok
7th March 2013, 07:31
Global motion stabilization.
New functions.
Begin...
.

##############################################################################
#
# Original script by g-force converted into a stand alone script by McCauley
# latest version from December 10, 2008
#
# http://forum.doom9.org/showthread.php?p=1222830#post1222830
#
##############################################################################

LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\DEPAN_20061128\depan.dll")
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\DEPAN_20061128\depanestimate.dll")
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\MVTOOLS-V2_5_11_3\mvtools2.dll")
LoadPlugIn("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\FFT3DFILTER_20070220\fft3dfilter.dll")
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\REMOVEGRAIN-1_0\repair.dll")


# Function Stab()
#
function Stab(clip clp, int "range", int "dxmax", int "dymax", float "trust", float "pixaspect", \
float "zoommax", int "mirror")
{
range = default(range, 1)
dxmax = default(dxmax, 4)
dymax = default(dymax, 3)
trust = default(trust, 0.0)
zoommax = default(zoommax, 1.0)
mirror = default(mirror, 0)

pixaspect = default(pixaspect, 1.094) # PAL 720x576
# pixaspect = default(pixaspect, 1.0) # PAL 768x576 (640x480)

temp = clp.TemporalSoften(7, 255, 255, 25, 2)
inter = Interleave(temp.Repair(clp.TemporalSoften(1, 255, 255, 25, 2)), clp)

# DePanEstimate(clip, int range, float trust, int winx, int winy, int dxmax, int dymax, \
# float zoommax, bool improve, float stab, float pixaspect, bool info, \
# string log, bool debug, bool show, bool fftw)
#
mdata = DePanEstimate(inter, \
dxmax = dxmax, \
dymax = dymax, \
pixaspect = pixaspect, \
zoommax = zoommax, \
improve = true, \
range = range, \
trust = trust)

# DePan(clip, clip data, float offset, int subpixel, float pixaspect, bool matchfields, \
# int mirror, int blur, bool info, string inputlog)
#
DePan(inter, \
data = mdata, \
pixaspect = pixaspect, \
subpixel = 2, \
mirror = mirror, \
matchfields = true, \
blur = 100, \
offset = -1)

return (SelectEvery(2, 0))
}



# Function Stab2()
#
function Stab2(clip clp, int "range", int "dxmax", int "dymax", float "trust", \
float "pixaspect", float "zoommax", float "rotmax", float "cutoff", \
bool "rot", int "mirror", bool "addzoom")
{
range = default(range, 2)
dxmax = default(dxmax, 4) # 4 : 3
dymax = default(dymax, 3) # 4 : 3
trust = default(trust, 2.0)

pixaspect = default(pixaspect, 1.094) # PAL 720x576
# pixaspect = default(pixaspect, 1.0) # PAL 768x576

addzoom = default(addzoom, true)
zoommax = default(zoommax, 1.05)
cutoff = default(cutoff, 0.1)
rot = default(rot, true)
rotmax = default(rotmax, 0.5)
mirror = default(mirror, 15)


# Global Motion Stabilization
# Глобальная стабилизация изображения
#
# DePanEstimate(clip, int range, float trust, int winx, int winy, int dxmax, int dymax, \
# float zoommax, bool improve, float stab, float pixaspect, bool info, \
# string log, bool debug, bool show, bool fftw)
#
mdata = DePanEstimate(clp, \
dxmax = dxmax, \
dymax = dymax, \
pixaspect = pixaspect, \
zoommax = zoommax, \
improve = true, \
range = range, \
trust = trust)

# function DePanStabilize(clip, clip data, float cutoff, float damping, bool addzoom, \
# int prev, int next, int mirror, int blur, int dxmax, int dymax, \
# float zoommax, float rotmax, int subpixel, float pixaspect, \
# int fitlast, float tzoom, bool info, string inputlog)
#
return (DepanStabilize(clp, \
data = mdata, \
dxmax = dxmax, \
dymax = dymax, \
prev = range, \
next = range, \
pixaspect = pixaspect, \
subpixel = 2, \
cutoff = cutoff, \
initzoom = 1.0, \
tzoom = 3.0, \
addzoom = addzoom, \
zoommax = zoommax, \
rotmax = rotmax, \
mirror = mirror, \
blur = 100, \
fitlast = 0, \
damping = 0.9, \
info = false))
}

Jenyok
7th March 2013, 07:33
Global motion stabilization.
New functions.
Continue...
.

# Function Stab3()
#
function Stab3(clip clp, int "range", int "dxmax", int "dymax", float "pixaspect", \
float "zoommax", float "rotmax", float "cutoff", \
bool "rot", int "mirror", bool "addzoom")
{
# Constants
# MSuper()
#
blkh = 8 ## Change this constant, must be 4, 8, 16, 32
blkv = 8 ## Change this constant, must be 4, 8, 16, 32
pel = 4
chroma = true
isse = true

# Constants
# MAnalyse()
#
blkh2 = blkh * 2 # Must be 4, 8, 16, 32
blkv2 = blkv * 2 # Must be 4, 8, 16, 32
(blkh2 > 32) ? 32 : blkh2
(blkv2 > 32) ? 32 : blkv2
overlap = blkh2 / 2
overlapV = blkv2 / 2
lambda = 100 * blkh2 * blkv2 / 64
lsad = 400 * blkh2 * blkv2 / 64


# Default variables values
#
dxmax = default(dxmax, 4) # 4 : 3
dymax = default(dymax, 3) # 4 : 3
range = default(range, 2)

pixaspect = default(pixaspect, 1.094) # PAL 720x576
# pixaspect = default(pixaspect, 1.0) # PAL 768x576

zoommax = default(zoommax, 1.05)
rotmax = default(rotmax, 0.5)
cutoff = default(cutoff, 0.1)
rot = default(rot, true)
mirror = default(mirror, 15)
addzoom = default(addzoom, true)


# Global Motion stabilization
# Глобальная стабилизация изображения
#
# function FFT3DFilter(clip, float "sigma", float "beta", int "plane", int "bw", int "bh", int "bt", int "ow", int "oh", \
# float "ratio", float "sharpen", float "scutoff", float "svr", float "smin", float "smax", bool "measure", \
# bool "interlaced", int "wintype", int "pframe", int "px", int "py", bool "pshow", float "pcutoff", \
# float "pfactor", float "sigma2", float "sigma3", float "sigma4", float "degrid", float "dehalo", \
# float "hr", float "ht", int "ncpu")
#
prefiltered = FFT3DFilter(clp, \
sigma = 3, \
plane = 4, \
bt = 4, \
sharpen = 0.75, \
interlaced = false, \
dehalo = 1.0, \
ncpu = 2)

# function MSuper(clip, int "hpad", int "vpad", int "pel", int "levels", bool "chroma", \
# int "sharp", int "rfilter", clip "pelclip", bool "isse", bool "planar")
#
prefilteredSuper = MSuper(prefiltered, \
hpad = blkh, \
vpad = blkv, \
pel = pel, \
levels = 1, \
chroma = chroma, \
sharp = 2, \
rfilter = 4, \
isse = isse, \
planar = false)

# function MAnalyse(clip super, int "blksize", int "blksizeV", int "level", int "search", int "searchparam", \
# int "pelsearch", bool "isb", int "lambda", bool "chroma", int "delta", bool "truemotion", \
# int "lsad", int "plevel", bool "global", int "pnew", int "pzero", int "pglobal", int "overlap", \
# int "overlapV", string "outfile", int "dct", int "divide", int "sadx264", int "badSAD", \
# int "badrange", bool "isse", int "full", bool "meander", bool "temporal")
#
vectors = MAnalyse(prefilteredSuper, \
blksize = blkh2, \
blksizeV = blkv2, \
overlap = overlap, \
overlapV = overlapV, \
isb = false, \
chroma = chroma, \
delta = 1, \
truemotion = false, \
global = true, \
dct = 5, \
search = 5, \
searchparam = 8, \
plevel = 0, \
divide = 0, \
pnew = 25, \
lsad = lsad, \
lambda = lambda, \
badSAD = 400, \
temporal = true, \
isse = isse)

# function MDepan(clip, clip vectors, clip "mask", bool "zoom", bool "rot", float "pixaspect", float "error", bool "info", \
# string "log", float "wrong", float "zerow", int "range", int "thSCD1", int "thSCD2", bool "isse", bool planar)
#
globalmotion = MDepan(prefiltered, \
vectors, \
pixaspect = pixaspect, \
range = range, \
zoom = addzoom, \
rot = rot, \
error = 80.0, \
wrong = 3.0, \
zerow = 0.05, \
thSCD1 = 625, \
thSCD2 = 160, \
isse = isse, \
info = false, \
planar = false)

# function DePanStabilize(clip, clip data, float cutoff, float damping, bool addzoom, \
# int prev, int next, int mirror, int blur, int dxmax, int dymax, \
# float zoommax, float rotmax, int subpixel, float pixaspect, \
# int fitlast, float tzoom, bool info, string inputlog)
#
return (DepanStabilize(clp, \
data = globalmotion, \
dxmax = dxmax, \
dymax = dymax, \
prev = range, \
next = range, \
pixaspect = pixaspect, \
subpixel = 2, \
rotmax = rotmax, \
initzoom = 1.0, \
tzoom = 3.0, \
addzoom = addzoom, \
zoommax = zoommax, \
mirror = mirror, \
blur = 300, \
cutoff = cutoff, \
damping = 0.9, \
fitlast = 0, \
info = false))
}

Jenyok
7th March 2013, 07:34
Global motion stabilization.
New functions.
End...
.

# Function Stab4()
#
function Stab4(clip clp, int "range", int "dxmax", int "dymax", float "pixaspect", \
float "zoommax", float "rotmax", float "cutoff", \
bool "rot", int "mirror", bool "addzoom")
{
# Constants
# MSuper()
#
blkh = 8 ## Change this constant, must be 4, 8, 16, 32
blkv = 8 ## Change this constant, must be 4, 8, 16, 32
pel = 4
chroma = true
isse = true
sharp = 2
rfilter = 2

# Constants
# MAnalyse()
#
blkh2 = blkh * 2 # Must be 4, 8, 16, 32
blkv2 = blkv * 2 # Must be 4, 8, 16, 32
(blkh2 > 32) ? 32 : blkh2
(blkv2 > 32) ? 32 : blkv2
overlap2 = blkh2 / 2
overlapV2 = blkv2 / 2
lambda = 100 * blkv2 * blkh2 / 64
lsad = 400 * blkv2 * blkh2 / 64
dct = 5
search = 5
searchparam = 8
pnew = 25
truemotion = false

# Constants
# MRecalculate()
#
blkhR = blkh # Must be 4, 8, 16, 32
blkvR = blkv # Must be 4, 8, 16, 32
overlapR = blkhR / 2
overlapVR = blkvR / 2
lambdaRecalc = 100 * blkvR * blkhR / 64


# Default variables values
#
dxmax = default(dxmax, 4) # 4 : 3
dymax = default(dymax, 3) # 4 : 3
range = default(range, 2)

pixaspect = default(pixaspect, 1.094) # PAL 720x576
# pixaspect = default(pixaspect, 1.0) # PAL 768x576

zoommax = default(zoommax, 1.05)
rotmax = default(rotmax, 0.5)
cutoff = default(cutoff, 0.1)
rot = default(rot, true)
mirror = default(mirror, 15)
addzoom = default(addzoom, true)


# Global Motion Stabilization
# Глобальная стабилизация изображения
#
# function FFT3DFilter(clip, float "sigma", float "beta", int "plane", int "bw", int "bh", int "bt", int "ow", int "oh", \
# float "ratio", float "sharpen", float "scutoff", float "svr", float "smin", float "smax", bool "measure", \
# bool "interlaced", int "wintype", int "pframe", int "px", int "py", bool "pshow", float "pcutoff", \
# float "pfactor", float "sigma2", float "sigma3", float "sigma4", float "degrid", float "dehalo", \
# float "hr", float "ht", int "ncpu")
#
prefiltered = FFT3DFilter(clp, \
sigma = 3, \
plane = 4, \
bt = 4, \
sharpen = 0.75, \
interlaced = false, \
dehalo = 1.0, \
ncpu = 2)

# function MSuper(clip, int "hpad", int "vpad", int "pel", int "levels", bool "chroma", \
# int "sharp", int "rfilter", clip "pelclip", bool "isse", bool "planar")
#
prefiltered2 = MSuper(clp, \
hpad = blkh, \
vpad = blkv, \
pel = pel, \
levels = 0, \
chroma = chroma, \
sharp = sharp, \
rfilter = rfilter, \
isse = isse, \
planar = false)

# function MSuper(clip, int "hpad", int "vpad", int "pel", int "levels", bool "chroma", \
# int "sharp", int "rfilter", clip "pelclip", bool "isse", bool "planar")
#
prefilteredSuper = MSuper(prefiltered, \
hpad = blkh, \
vpad = blkv, \
pel = pel, \
levels = 1, \
chroma = chroma, \
sharp = sharp, \
rfilter = rfilter, \
isse = isse, \
planar = false)

# function MAnalyse(clip super, int "blksize", int "blksizeV", int "level", int "search", int "searchparam", \
# int "pelsearch", bool "isb", int "lambda", bool "chroma", int "delta", bool "truemotion", \
# int "lsad", int "plevel", bool "global", int "pnew", int "pzero", int "pglobal", int "overlap", \
# int "overlapV", string "outfile", int "dct", int "divide", int "sadx264", int "badSAD", \
# int "badrange", bool "isse", int "full", bool "meander", bool "temporal")
#
vectors = MAnalyse(prefiltered2, \
blksize = blkh2, \
blksizeV = blkv2, \
overlap = overlap2, \
overlapV = overlapV2, \
isb = false, \
chroma = chroma, \
delta = 1, \
temporal = true, \
search = search, \
searchparam = searchparam, \
dct = dct, \
plevel = 0, \
pnew = pnew, \
lambda = lambda, \
lsad = lsad, \
truemotion = truemotion, \
global = true, \
divide = 0, \
badSAD = 400, \
isse = isse)

# function MRecalculate(clip super, clip vectors, int "thSAD", int "smooth", int "blksize", int "blksizeV", \
# int "search", int "searchparam", int "lambda", bool "chroma", bool "truemotion", \
# int "pnew", int "overlap", int "overlapV", string "outfile", int "dct", int "divide", \
# int "sadx264", bool "isse")
#
vectorsRecalc = MRecalculate(prefilteredSuper, \
vectors, \
blksize = blkhR, \
blksizeV = blkvR, \
overlap = overlapR, \
overlapV = overlapVR, \
search = search, \
searchparam = searchparam, \
dct = dct, \
lambda = lambdaRecalc, \
pnew = pnew, \
truemotion = truemotion, \
thsad = 100)

# function MDepan(clip, clip vectors, clip "mask", bool "zoom", bool "rot", float "pixaspect", float "error", bool "info", \
# string "log", float "wrong", float "zerow", int "range", int "thSCD1", int "thSCD2", bool "isse", bool planar)
#
globalmotion = MDepan(prefiltered, \
vectorsRecalc, \
zoom = addzoom, \
rot = rot, \
pixaspect = pixaspect, \
error = 80.0, \
info = false, \
wrong = 3.0, \
zerow = 0.05, \
range = range, \
thSCD1 = 625, \
thSCD2 = 160, \
isse = isse, \
planar = false)

# function DePanStabilize(clip, clip data, float cutoff, float damping, bool addzoom, \
# int prev, int next, int mirror, int blur, int dxmax, int dymax, \
# float zoommax, float rotmax, int subpixel, float pixaspect, \
# int fitlast, float tzoom, bool info, string inputlog)
#
return (DepanStabilize(clp, \
data = globalmotion, \
dxmax = dxmax, \
dymax = dymax, \
prev = range, \
next = range, \
pixaspect = pixaspect, \
subpixel = 2, \
initzoom = 1.0, \
tzoom = 3.0, \
addzoom = addzoom, \
zoommax = zoommax, \
mirror = mirror, \
rotmax = rotmax, \
blur = 300, \
cutoff = cutoff, \
damping = 0.9, \
fitlast = 0, \
info = false))

}

lisztfr9
7th March 2013, 12:35
here's a newer version of the script that thetoof posted. Give it a shot. You might need to play around with dxmax and dymax.

temp = last.TemporalSoften(7,255,255,25,2)
Interleave(temp.Repair(last.TemporalSoften(1,255,255,25,2)),last)
DePan(last,data=DePanEstimate(last,trust=0,dxmax=10,dymax=10),offset=-1)
SelectEvery(2,0)

-G

Are you sure you need the repair filter here ?

Thanks, L

Mystery Keeper
7th March 2013, 14:28
I could try to make a stabilization plugin. But there's a problem. How do I deal with subpixel offset? I understand how to move pixels by integer offset, but how do I deal with fractional? Do I have to fit a surface and inpaint the interpolated values?

SEt
9th March 2013, 18:29
You can use resize algorithm with scaling factor 1 for that.

alexx7777
12th November 2017, 03:17
I can not understand in any way what better values ​​to set for dxmax and dymax function Stab () to remove strong shaking (720x576, 50p)?

raffriff42
12th November 2017, 04:46
I can not understand in any way what better values ​​to set for dxmax and dymax function Stab () to remove strong shaking (720x576, 50p)?I use Deshaker myself, but I find pass 2 motion smoothness (Depan equivalent: DePanStabilize "cutoff") to be very important for cancelling strong shaking. It needs to be tuned to the predominant shake frequency.

alexx7777
12th November 2017, 18:09
I use Deshaker myself, but I find pass 2 motion smoothness (Depan equivalent: DePanStabilize "cutoff") to be very important for cancelling strong shaking. It needs to be tuned to the predominant shake frequency.

Thanks you! I wanted to
find out for what and what are better for dxmax and dymax?

poisondeathray
13th November 2017, 02:05
Thanks you! I wanted to
find out for what and what are better for dxmax and dymax?

What have you tried so far ?

Try some other values :devil:


But seriously it's just trial and error. Different values might be appropriate for different videos. "6 and 9" might be great for my video but not for yours. Play with the settings. Maybe try other stabilization software . If you still can't get something salvagable post a sample clip

raffriff42
13th November 2017, 03:06
I'm looking through the Depan docs (http://avisynth.org.ru/depan/depan.html) and I'm not finding some very important features that Deshaker (http://www.guthspot.se/video/deshaker.htm) has.

- ignore pixels outside <area>
- ignore pixels inside <area>
These two let you tell Deshaker to ignore some part of the frame that has a different motion from the main content
(example: w/ helmet cam, ignore the helmet and focus on the world outside)

- Discard motion of blocks that have match value less than X
- Deep analysis if less than X percent of vectors are ok
...and related items. In combination with Pass 1 block visualization (video output=motion vectors), lets you tune out incorrect motion sensing.

- Motion smoothness. Like I said before, very important.

- Edge compensation / concealment. Lots of choices. (blend frames, color wash, zoom in, ...)

- and a biggie, rolling shutter compensation.

I'm sorry, Deshaker is just better (it seems to me). Here (https://www.dropbox.com/s/tu2dx2slc41esul/Deshaker-raff4-defaults.png?dl=0) are the settings I use as a starting point. The highlighted ones are the ones to spend time with. The settings that are blurred out are different for every video, or for Edge Compensation, personal preference.

alexx7777
13th November 2017, 12:39
What have you tried so far ?

Try some other values :devil:


But seriously it's just trial and error. Different values might be appropriate for different videos. "6 and 9" might be great for my video but not for yours. Play with the settings. Maybe try other stabilization software . If you still can't get something salvagable post a sample clip

Different values ​​from minus to plus (from -40 to 40).

alexx7777
13th November 2017, 12:43
I'm looking through the Depan docs (http://avisynth.org.ru/depan/depan.html) and I'm not finding some very important features that Deshaker (http://www.guthspot.se/video/deshaker.htm) has.

- ignore pixels outside <area>
- ignore pixels inside <area>
These two let you tell Deshaker to ignore some part of the frame that has a different motion from the main content
(example: w/ helmet cam, ignore the helmet and focus on the world outside)

- Discard motion of blocks that have match value less than X
- Deep analysis if less than X percent of vectors are ok
...and related items. In combination with Pass 1 block visualization (video output=motion vectors), lets you tune out incorrect motion sensing.

- Motion smoothness. Like I said before, very important.

- Edge compensation / concealment. Lots of choices. (blend frames, color wash, zoom in, ...)

- and a biggie, rolling shutter compensation.

I'm sorry, Deshaker is just better (it seems to me). Here (https://www.dropbox.com/s/tu2dx2slc41esul/Deshaker-raff4-defaults.png?dl=0) are the settings I use as a starting point. The highlighted ones are the ones to spend time with. The settings that are blurred out are different for every video, or for Edge Compensation, personal preference.
Thank you! I've already tried it, I'll try again