Printable Version of Topic
Click here to view this topic in its original format
Unofficial VirtualDub Support Forums > Newbie Questions > [speeding Up Video] Error Avysinth Code


Posted by: tigretones Feb 19 2014, 07:55 PM
Hi everybody,

I'm trying to speed up just some parts of a video, and I found great help in http://forums.virtualdub.org/index.php?act=ST&f=4&t=21806&st=0 in the forum. But unfortunately I can't get my code to work, VirtualDub always shows me the same warning message:

AvySinth open failure:
Evaluate: operands of '+' must both be numbers, strings or clips
(C:\Documents and Settings\Pc1\Escritorio\Tapon14-02-17\Nuevo Avysinth Script.avs, line 11)


The code is:

CODE
#avisynth
## speed change test:
##   speed x 50 from frame 0 to frame 26464;
##   normal speed from frame 26465 to frame 26883
##   speed x 50 to end of video

V=AviSource ("C:\Documents and Settings\Pc1\Escritorio\Tapon14-02-17<!--POST BOX-->Punto de partida.avi")

return UUChangeSpeed(Trim(V, 0, 26464), 50)
\  + Trim(V, 26465, 26883)
\  + UUChangeSpeed(Trim(V, 26884, 0), 50)

function UUChangeSpeed(clip c, float factor)
{
oldRate = FrameRate(c)
newVid = AssumeFPS(c, oldRate * factor)
}


As you can see, I'm trying to speed up the video from the beggining to frame 26464, then return to normal speed until frame 26883, and finally speed up again the video until the end.

Any ideas about what am I doing wrong?

Thanks in advance.

Posted by: dloneranger Feb 19 2014, 08:05 PM
the function doesn't return anything
add return newvid at the end

....then you'll get a framerates don't match error instead

Posted by: malky Feb 19 2014, 10:42 PM
newVid = AssumeFPS(c, oldRate * factor)
return AudioDub(ChangeFPS(newVid, c, linear=false),c.TimeStretch(tempo=100*factor))

}

I inserted the "return Audiodub" line.
The 'linear=false' is required when the float factor is more than 10;your scripts shows a factor of 50.

Posted by: tigretones Feb 20 2014, 10:37 AM
Thank you very much for your answers guys, I really appreciate your help.

@Malky: the video has no audio. If I include the "return Audiodub" line in the code, VirtualDub returns me the following error message:

Avysinth open failure:
AudioDub: need an audio and a video track


So I decided to delete that line, now I see that was a bit radical, the function needs an end.

@Dlonerange: I've just added the end of function you suggest, and it works... partially, because now I get a new error message:

Avysinth open failure:
Splice: video framerate doesn't match
(C:\Documents and Settings\Pc1\Escritorio\Tapon14-02-17\Nuevo Avysinth Script.avs, line 11)


At this point, the code is
QUOTE
#avisynth
## speed change test:
##  speed x 50 from frame 0 to frame 26464;
##  normal speed from frame 26465 to frame 26883
##  speed x 50 to end of video

V=AviSource ("C:\Documents and Settings\Pc1\Escritorio\Tapon14-02-17<!--POST BOX-->Punto de partida.avi")

return UUChangeSpeed(Trim(V, 0, 26464), 50)
\  + Trim(V, 26465, 26883)
\  + UUChangeSpeed(Trim(V, 26884, 0), 50)

function UUChangeSpeed(clip c, float factor)
{
oldRate = FrameRate©
newVid = AssumeFPS(c, oldRate * factor)
return newVid
}


Anyone knows where's the new mistake?

Posted by: dloneranger Feb 20 2014, 12:55 PM
It's not a mistake, just a limit on joining video together
Avisynth will only join them if they're the same size and fps

You should be able to just remove the audiodub from malky's suggestion
(I don't have avisynth here atm so can't check)

newVid = AssumeFPS(c, oldRate * factor)
return ChangeFPS(newVid, c, linear=false)
}

Posted by: raffriff42 Feb 20 2014, 01:29 PM
Sorry, that code was written in a hurry, and not tested at the extremes. Thanks for the input.
Here's a new, improved function that blends frames when possible. It handles video-only clips and any reasonable conversion factor:

EDIT: additional debugging; pitch correction now optional; added frame blending in fast forward.
CODE
#######################################
### change speed over a wide range
### with frame blending in fast forward by default.
##
## @ factor - 0.33 for 1/3 speed, etc;
##    min = 0.001; max = min(FrameCount, 1000)
##    (if > FrameCount, duration would be 0);
##    if argument is out of range, an error occurs.
##
## @ pitchfix - if true, maintain audio pitch with speed
##    (default false; allow pitch to rise or fall)
##
## @ noblend - if true, never blend frames (default false)
##
## @ raffriff42 24-Feb-2014
##
function UUChangeSpeed2(
\           clip C, float factor,
\           bool "pitchfix", bool "noblend")
{
   Assert(factor>=0.001,
   \  "UUChangeSpeed2 bad argument: factor<0.001")
   Assert(factor<=1000.0,
   \  "UUChangeSpeed2 bad argument: factor>1000")
   Assert(factor<=C.FrameCount,
   \  "UUChangeSpeed2 bad argument: factor>FrameCount")

   pitchfix = Default(pitchfix, false)
   noblend  = Default(noblend, false)

   AS = C.AssumeFPS(C.FrameRate * factor)

   temprad = Round(0.5 * factor)
   TS = (factor<1.0 || temprad==0 || noblend)
   \  ? AS
   \  : Overlay(
   \       AS,
   \       AS.TemporalSoften(
   \           temprad, 255, 255, 48, 2),
   \       opacity=0.7)

   (factor<1.5 && noblend==false)  
   \  ? AS.ConvertFPS(C)
   \  : TS.ChangeFPS(C.Framerate, linear=(factor<10.0))

   A = (pitchfix)
   \  ? C.TimeStretch(tempo=factor*100.0)
   \  : C.TimeStretch(rate=factor*100.0)

   return (C.HasAudio==false) ? Last : Last.AudioDub(A)
}

Posted by: tigretones Feb 20 2014, 07:52 PM
@Dloneranger: It worked! I added those new lines and the video loaded in VirtualDub, with no errors and the speed changes I wanted! Thank you sooooooooooo much, that script has saved me a lot of time!

I copy the right code here, just in case it may be useful to any newbie like me:

QUOTE
#avisynth
## speed change test:
##  speed x 50 from frame 0 to frame 26464;
##  normal speed from frame 26465 to frame 26883
##  speed x 50 to end of video

V=AviSource ("C:\Documents and Settings\Pc1\Escritorio\Tapon\2014-02-17\00Punto de partida.avi")

return UUChangeSpeed(Trim(V, 0, 26464), 50)
\  + Trim(V, 26465, 26883)
\  + UUChangeSpeed(Trim(V, 26884, 0), 50)

function UUChangeSpeed(clip c, float factor)
{
oldRate = FrameRate©
newVid = AssumeFPS(c, oldRate * factor)
return ChangeFPS(newVid, c, linear=false)
}


@raffriff42:Thanks to you too! I can't tell you if the new code works because I haven't tested it yet. I'll need some time to understand it, seems quite more difficult...

Powered by Invision Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)