View Full Version : Replacing video
Shubin
29th July 2003, 10:36
Hello ! I'm new to AviSynth so here is the question.
What I want to do:
replace a small part of video track with another video
while preserving audio track. I need this because I want
to hide some mistakes : mis-handling of camera, bad transitions
etc.
What I do for this :
#replace part of x1 with y
x1=avisource("rrr.avi").converttorgb32
y=avisource("www.avi").trim(1,20).converttorgb32
#split x1
p1=trim(x1,0,20)
p2=trim(x1,21,30)
p3=trim(x1,31,0)
#replace
q1=layer(p2,y,"add")
#return result
p1+q1+p3
Is this a best way ?
I found that what seems to be the proper solution
x1=avisource("rrr.avi").converttorgb32
y=avisource("www.avi").trim(1,20).converttorgb32
applyrange(x1,21,30,"layer",y,"add")
does not work : it replaces the part of x1 with the _first frame_
of y.
Is it bug or feature ?
What is the best way to do the job ?
Wilbert
29th July 2003, 10:47
You don't need to convert to RGB32.
I found that what seems to be the proper solution
x1=avisource("rrr.avi").converttorgb32
y=avisource("www.avi").trim(1,20).converttorgb32
applyrange(x1,21,30,"layer",y,"add")
does not work : it replaces the part of x1 with the _first frame_ of y.
Is it bug or feature ?
I guess it doesn't work because the arguments of ApplyRange (except the first one) can't be a clip. You probably can get it to work with Animate.
Shubin
29th July 2003, 11:04
Originally posted by Wilbert
You don't need to convert to RGB32.
I need, because "layer" does not work without it.
I guess it doesn't work because the arguments of ApplyRange (except the first one) can't be a clip. You probably can get it to work with Animate.
You guess it wrong. Animate does not work either.
animate(x1,21,30,"layer",y,"add",y,"add")
replaces all the rest of x1 with first and last frames of y...
cweb
29th July 2003, 16:38
Layer works in yuy2 also, so you can convert to that instead of rgb32.
Dont forget the return statement:[code]
#return result
last = p1+q1+p3
return last
Wilbert
29th July 2003, 20:11
Return statement doesn't matter, you can leave it off.
You are right, I guess it's a bug:
x1=AviSource("e:\pdwork\atomic.avi")
y=BicubicResize(x1, 320, 240).Trim(0, 40)
animate(x1, 21, 40, "layer", y, "add", 128, 0, 0, y, "add", 128, 0, 0)
1) The layering is during the whole return clip. The overlay clip starts playing at frame 0 instead of 21.
2) After frame 40 the layering continues, where the overlay clip consists of the last frame of y.
stickboy
30th July 2003, 05:47
Yeesh. You guys don't need to use Layer or Animate or any of that.
Here's how I would solve the original problem:
c1 = AVISource("clip1.avi")
c2 = AVISource("clip2.avi")
# splice c2 into c1
c1.Trim(0, 1000) + c2.Trim(123, 623) + c1.Trim(1500, 0)
# use c1's original audio track
AudioDub(last, c1)
Shubin
30th July 2003, 06:27
Originally posted by stickboy
Here's how I would solve the original problem:
c1 = AVISource("clip1.avi")
c2 = AVISource("clip2.avi")
# splice c2 into c1
c1.Trim(0, 1000) + c2.Trim(123, 623) + c1.Trim(1500, 0)
# use c1's original audio track
AudioDub(last, c1)
Thanks. I'll try it. Actually I tried to get audio
from clip using wavsource, glue video together and attach
audio back, but it caused a sufficient desync between audio
and video. Also one should be very careful in counting frames
of clips to get audio in sync. My first method is less
sensitive to this.
stickboy
30th July 2003, 06:45
Also one should be very careful in counting framesDoh! You're right. In my original post, I cut out frames [1001, 1499] in c1 (499 frames) but inserted frames [123, 623] from c2 (501 frames).
(You'd think after my thread about the subtle problems with Trim (http://forum.doom9.org/showthread.php?s=&threadid=58358) that I would have been more careful.)
Well, if I had used my Trim2 or Trim3 functions (http://forum.doom9.org/showthread.php?s=&threadid=58358), it would've been less troublesome. :)
n = 500;
c1.Trim2(0, 1000) + c2.Trim2(123, 123 + n) + c1.Trim2(1000 + n)
AudioDub(last, c1)
Of course, a function would be even easier:
# ReplaceVideo
#
# Replaces frames from one clip with those from another. Does
# not affect the audio.
#
# PARAMETERS:
# baseClip - the target clip
# newClip - the clip containing the replacement frames
# startIndex - the frame number in baseClip where replacement should
# begin
# length - the number of frames to replace in baseClip;
# default: newClip.FrameCount()
#
function ReplaceVideo(clip baseClip, clip newClip, int startIndex, int "length")
{
length = default(length, newClip.FrameCount())
assert(length <= newClip.FrameCount(), "ReplaceVideo: invalid length")
seg1 = baseClip.Trim2(0, startIndex)
seg2 = newClip.Trim2(0, length=length)
seg3 = baseClip.Trim2(startIndex + length)
seg1 + seg2 + seg3
assert(last.FrameCount() == baseClip.FrameCount(), "ReplaceVideo: bad math")
return AudioDub(last, baseClip)
}
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.