View Full Version : Move/shift frames without crop
Great Dragon
20th April 2015, 16:28
Hello,
Is there any better way to move several frames in a clip to left or right?
For now the only way I see to do it is to use trim and crop. Like this:
S=source #100 frames
s1=S.trim(0,50).crop(4,0,0,0).addborders(0,0,0,4)
s2=S.trim(51,0).crop(0,0,0,2).addborders(2,0,0,0)
s1++s2
It would be nice to have something like this:
source.move(0,50,left=4).move(51,0,right=2)
StainlessS
20th April 2015, 17:19
Take a look at ApplyRange(), not on Wiki but is here: http://avisynth.org.ru/docs/english/corefilters/animate.htm
Not ideal.
creaothceann
20th April 2015, 17:46
Use with ApplyRange:
function MoveLeft (clip c, int i) {c.Move(-i, 0)}
function MoveRight(clip c, int i) {c.Move( i, 0)}
function MoveUp (clip c, int i) {c.Move( 0, -i)}
function MoveDown (clip c, int i) {c.Move( 0, i)}
function Move(clip c, int dx, int dy) {
c
IsRGB ? Move_RGB(dx, dy)
\ : c.BlankClip.Overlay(c, dx, dy)
}
function Move_RGB(clip c, int dx, int dy) {
c.ConvertToRGB32
last.BlankClip.Layer(last, x=dx, y=dy)
(c.IsRGB24) ? ConvertToRGB24 : last
}
(For some reason Avisynth complains when I move the code in the function behind "IsRGB?"...)
Reel.Deel
20th April 2015, 18:01
Couldn't this be done with just Animate and PointResize? I think I've seen a script that does this.
Take a look at ApplyRange(), not on Wiki but is here:
It's indeed in the wiki: http://avisynth.nl/index.php/Animate
StainlessS
20th April 2015, 19:06
Thanx RD, When I did google search I got an empty page with just the name on wiki.
How bout diss
Function ShiftClip(clip c,Int "HDir",Int "VDir",Int "BordCol") {
c
HDir = Default(HDir,0) VDir = Default(VDir,0) BordCol = Default(BordCol,0)
LCrop = (HDir<0) ? -HDir : 0 RCrop = (HDir>0) ? HDir : 0
TCrop = (VDir<0) ? -VDir : 0 BCrop = (VDir>0) ? VDir : 0
Crop(LCrop,TCrop,-RCrop,-BCrop)
Addborders(RCrop,BCrop,LCrop,TCrop,BordCol)
Return Last
}
Function Move(clip c,Int "S", Int "E", Int "HDir", Int "VDir",Int "BordCol") {
/*
Shift Has to comply with Colorspace crop restrictions, Best RGB or YV24.
Start and End Args may not be Exactly like trim
Move(0,0) # Entire clip
Move(100,0) # Frame 100 to End of Clip
Move(0,-1) # Frame 0 Only
Move(1,1) # Frame 1 Only
Move(1,-1) # Frame 1 Only
Move(1) # Frame 1 Only
Move(1,-3) # Frames 1 to 3 (ie 3 frames)
move(100,200) # Frames 100 to 200
move(100,-50) # Frames 100 to 149 ie 50 frames
*/
c
FC=FrameCount-1
S = Min(Max(Default(S,0),0),FC)
E = Default(E,-1)
E = (E==0) ? FrameCount -1 : E
E = Min(((E < 0) ? S-E-1 : E),FC)
ApplyRange(S,E,"ShiftClip",HDir,VDir,BordCol)
}
Avisource("D:\avs\test.avi")
#RoboCrop(WMod=4)
ShowFrameNumber
#Move(0,0,HDir=0,VDir=32,BordCol=$FF0000)
#Move(100,0,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(0,-1,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(1,1,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(1,-1,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(1,HDir=32,VDir=32,BordCol=$FFFF00)
#Move(1,-3,HDir=-32,VDir=-32,BordCol=$FFFF00)
#Move(100,200,HDir=32,VDir=0,BordCol=$00FFFF)
#Move(100,-50,HDir=32,VDir=0,BordCol=$00FFFF)
EDIT: Removed Debugging stuff
StainlessS
20th April 2015, 20:13
Or this for single pixels shift for eg YV12 using PointResize as suggested by Reel.Deel (NOT For Interlaced).
Function ShiftClip(clip c,Int "HDir",Int "VDir",Int "BordCol") {
c
HDir = Default(HDir,0) VDir = Default(VDir,0) BordCol = Default(BordCol,0)
LCrop = (HDir<0) ? -HDir : 0 RCrop = (HDir>0) ? HDir : 0
TCrop = (VDir<0) ? -VDir : 0 BCrop = (VDir>0) ? VDir : 0
XM = RT_ColorSpaceXMod() YM = RT_ColorSpaceYMod(Laced=False) # NOT for Interlaced
(XM!=1 || YM!=1) ? PointResize(c.Width*XM,c.Height*YM) : NOP
Crop(LCrop*XM,TCrop*YM,-RCrop*XM,-BCrop*YM)
Addborders(RCrop*XM,BCrop*YM,LCrop*XM,TCrop*YM,BordCol)
(XM!=1 || YM!=1) ? PointResize(c.Width,c.Height) : NOP
Return Last
}
Function Move(clip c,Int "S", Int "E", Int "HDir", Int "VDir",Int "BordCol") {
/*
Start and End Args may not be Exactly like trim
Move(0,0) # Entire clip
Move(100,0) # Frame 100 to End of Clip
Move(0,-1) # Frame 0 Only
Move(1,1) # Frame 1 Only
Move(1,-1) # Frame 1 Only
Move(1) # Frame 1 Only
Move(1,-3) # Frames 1 to 3 (ie 3 frames)
move(100,200) # Frames 100 to 200
move(100,-50) # Frames 100 to 149 ie 50 frames
*/
c
FC=FrameCount-1
S = Min(Max(Default(S,0),0),FC)
E = Default(E,-1)
HDir = Default(HDir,0) VDir = Default(VDir,0) BordCol = Default(BordCol,0)
E = (E==0) ? FrameCount -1 : E
E = Min(((E < 0) ? S-E-1 : E),FC)
ApplyRange(S,E,"ShiftClip",HDir,VDir,BordCol)
}
Avisource("D:\avs\test.avi")
RoboCrop(WMod=4,Laced=False)
ShowFrameNumber
#ConvertToYV12 # Test using Point Resize
ConvertToRGB32 # Test WITHOUT using Point Resize
Move(0,0,HDir=1,VDir=1,BordCol=$FF0000) # Test colorspace crop restriction
#Move(100,0,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(0,-1,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(1,1,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(1,-1,HDir=0,VDir=-32,BordCol=$FF0000)
#Move(1,HDir=32,VDir=32,BordCol=$FFFF00)
#Move(1,-3,HDir=-32,VDir=-32,BordCol=$FFFF00)
#Move(100,200,HDir=32,VDir=0,BordCol=$00FFFF)
#Move(100,-50,HDir=32,VDir=0,BordCol=$00FFFF)
EDITED: Added conditional PointResize, although I think it may make no difference, think resizers return original clip
if same size clip as original and without croppings (ie PointResize not linked into filter graph).
EDIT: Requires RT_Stats for RT_ColorSpaceXmod/YMod.
EDIT: Below untested but should (I think) work OK
Function MrX(clip c,int "S", Int "E", Int "X") {Move(c,S=S,E=E,HDir=X)} # Move range (default border col)
Function MrY(clip c,int "S", Int "E", Int "Y") {Move(c,S=S,E=E,VDir=Y)}
Function MfX(clip c,int "S", Int "X") {Move(c,S=S, HDir=X)} # Move frame (default border col)
Function MfY(clip c,int "S", Int "Y") {Move(c,S=S, VDir=Y)}
Great Dragon
20th April 2015, 23:00
Thanks to everyone.
StainlessS, your solution works like a charm. Even in YV12 colorspace with 1px shift.
StainlessS
27th April 2015, 12:51
Post #6, Does not seem to set border under v2.58 when adding single pixel to bottom and/or right hand side,
guessing something to do with chroma placement in old v2.58 (with colored border, ie remains black).
StainlessS
11th May 2015, 21:25
Thought this might come in handy so posting here too. http://avisynth.nl/index.php/File:ChromaShiftSP.avsi
#ChromaShift_SP: Shift chroma with subpixel accuracy, basic function by IanB, made standalone by McCauley
function ChromaShiftSP (clip clp, float "X",float "Y") {
X = default(X, 0.0) # positive values shift the chroma to left, negative values to right
Y = default(Y, 0.0) # positive values shift the chroma upwards, negative values downwards
w = clp.Width()
h = clp.Height()
clp.MergeChroma(clp.Spline16Resize(w, h, X, Y, w+X, h+Y)) }
Function MoveChroma(clip c,Int "S", Int "E", Float "X", Float "Y") {
/*
Start and End Args may not be Exactly like trim
Move(0,0) # Entire clip
Move(100,0) # Frame 100 to End of Clip
Move(0,-1) # Frame 0 Only
Move(1,1) # Frame 1 Only
Move(1,-1) # Frame 1 Only
Move(1) # Frame 1 Only
Move(1,-3) # Frames 1 to 3 (ie 3 frames)
move(100,200) # Frames 100 to 200
move(100,-50) # Frames 100 to 149 ie 50 frames
*/
c
FC=FrameCount-1
S = Min(Max(Default(S,0),0),FC)
E = Default(E,-1)
X=Default(X,0.0) Y=Default(X,0.0)
E = (E==0) ? FrameCount -1 : E
E = Min(((E < 0) ? S-E-1 : E),FC)
ApplyRange(S,E,"ChromaShiftSP",X,Y)
}
Avisource("D:\avs\test.avi")
MoveChroma(100,0,64,64)
EDIT: Added range selection.
EDIT: -ve X shift seems to not work quite correct (leaves some rubbish on frame, -ve Y not quite as bad[v2.6, perhaps 2.6 chroma placement])
EDIT: Can someone with v2.58 test it out and see what happens.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.