Printable Version of Topic
Click here to view this topic in its original format
Unofficial VirtualDub Support Forums > Newbie Questions > Speeding Up Sections Of A Video.


Posted by: Virtualnoob123 Sep 25 2013, 06:28 PM
Hi all,

Yeah, I want to increase the frame rate for a section of video, but can't seem to get any answers on how to do it. It has audio that will need speeding up too.

I can speed up the hole video using Virtualdub's Video Frame Rate Control tab. And I know how to sync the audio too using the Input > Stretch > Output, but I can't seem to increase the fps for a section of video.

I tried to cut the clips into section and then edit the frame rates, then tried to stick them back together with append AVI segments. That never worked either. Kept getting an error.

Can anyone tell me how to do this?

Thanks.

Posted by: Altaf Sep 25 2013, 07:58 PM
Example 23.97600<25.00000:
http://radikal.ru/fp/9e17d9ba833a4284a78116373c731627

Posted by: raffriff42 Sep 25 2013, 08:02 PM
I can get it to work like this, but I recommend another way (see my Avisynth script below)
  • select clip to be changed
  • add Interpolate filter; scale frame rate by 1 / (new speed)
    in other words, to speed up by 30%, new speed is 1.30;
    so scale frame rate by (1/1.30) or 0.77
    EDIT Altaf's frame rate conversion above does the same thing, but without frame blending.
  • save using a lossless codec; this video will have a slower frame rate (tempfile_1)
    (assuming your normal frame rate is 30, new rate = 30 * 0.77 = 23.1 fps)
  • open tempfile_1 in VirtualDub; Video menu, Frame rate, convert input to 30
  • save again using a lossless codec; this video will be 30fps with a fast motion effect (tempfile_2)
  • now you can add tempfile_2 together with your normal-speed clips.
(totally ignoring audio here)

OK, now let's do it the http://avisynth.nl/index.php/Main_Page way - in fact let's do a slowdown and a speedup, with matching audio speed changes @ constant pitch, all with no temp files:
  • Install Avisynth;
  • Copy this code and save as "something.avs" (as plain text of course)
  • Edit "D:\<path>\test.avi" to point to your source video
  • Open in VirtualDub. Compress. Done!
CODE
#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource("D:\<path>\test.avi")
return UUChangeSpeed(Trim(V, 0, 29), 0.5)
\    + UUChangeSpeed(Trim(V, 30, 149), 1.3)
\    + Trim(V, 150, 0)

function UUChangeSpeed(clip c, float factor)
{
  oldRate = FrameRate(c)
  newVid = AssumeFPS(c, oldRate * factor)
  return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


UPDATE - new change speed function
http://forums.virtualdub.org/index.php?act=ST&f=4&t=22174&st=0&#entry95457

Posted by: Virtualnoob123 Sep 25 2013, 08:11 PM
QUOTE (Altaf @ Sep 25 2013, 07:58 PM)
Example 23.97600<25.00000:
http://radikal.ru/fp/9e17d9ba833a4284a78116373c731627

I'm not sure what you're trying to tell me there, m8 smile.gif



Posted by: Virtualnoob123 Sep 25 2013, 08:23 PM
QUOTE (raffriff42 @ Sep 25 2013, 08:02 PM)
I can get it to work like this, but I recommend another way (see my Avisynth script below)
  • select clip to be changed
  • add Interpolate filter; scale frame rate by 1 / (new speed)
    in other words, to speed up by 30%, new speed is 1.30;
    so scale frame rate by (1/1.30) or 0.77
    EDIT Altaf's frame rate conversion above does the same thing, but without frame blending.
  • save using a lossless codec; this video will have a slower frame rate (tempfile_1)
    (assuming your normal frame rate is 30, new rate = 30 * 0.77 = 23.1 fps)
  • open tempfile_1 in VirtualDub; Video menu, Frame rate, convert input to 30
  • save again using a lossless codec; this video will be 30fps with a fast motion effect (tempfile_2)
  • now you can add tempfile_2 together with your normal-speed clips.
(totally ignoring audio here)

OK, now let's do it the http://avisynth.nl/index.php/Main_Page way - in fact let's do a slowdown and a speedup, with matching audio speed changes @ constant pitch, all with no temp files:
  • Install Avisynth;
  • Copy this code and save as "something.avs" (as plain text of course)
  • Edit "D:\<path>\test.avi" to point to your source video
  • Open in VirtualDub. Compress. Done!
CODE
#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource("D:\<path>\test.avi")
return UUChangeSpeed(Trim(V, 0, 29), 0.5)
\    + UUChangeSpeed(Trim(V, 30, 149), 1.3)
\    + Trim(V, 150, 0)

function UUChangeSpeed(clip c, float factor)
{
  oldRate = FrameRate(c)
  newVid = AssumeFPS(c, oldRate * factor)
  return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}

Ok, I downloaded that software and copied and pasted the code into a text file.

I edited the the file path, saved, but I'm unsure what you mean by open Virtualdub and compress.

I'm a bit of a noob, so you'll need to explain a bit more.

If you mean open that avs file with Virtualdub then I get an error about line 7 column 14.

Code is like this atm:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps
return UUChangeSpeed(Trim(V, 0, 29), 0.5)
\    + UUChangeSpeed(Trim(V, 30, 149), 1.3)
\    + Trim(V, 150, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}



Posted by: raffriff42 Sep 25 2013, 08:45 PM
You open "something.avs" in VirtualDub as if it was a video file. Avisynth reads the source, does the processing according to the instructions in the script, and passes the video to VirtualDub (or other Avisynth-compatible program), a frame at a time.

It's called frameserving, and it's kind of hard to get your head around, I admit. It helps to read some of the introductory articles at avisynth.nl

Posted by: Virtualnoob123 Sep 25 2013, 08:48 PM
QUOTE (raffriff42 @ Sep 25 2013, 08:45 PM)
You open "something.avs" in VirtualDub as if it was a video file. Avisynth reads the source, does the processing according to the instructions in the script, and passes the video to VirtualDub (or other Avisynth-compatible program), a frame at a time.

It seems the code is wrong somehow. I'm getting errors.

Is the code correct:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource (D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps)

return UUChangeSpeed(Trim(V, 0, 29), 0.5)
\    + UUChangeSpeed(Trim(V, 30, 149), 1.3)
\    + Trim(V, 150, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


I get a line 7 column 15 error with that code now.

Posted by: raffriff42 Sep 25 2013, 08:49 PM
(deleted - see my next post)

Posted by: Virtualnoob123 Sep 25 2013, 08:51 PM
QUOTE (raffriff42 @ Sep 25 2013, 08:49 PM)
What error message, exactly?

Virtualdub error

Script error expected a, or )
(:\User\Gareth\Desktop\test.avs, line 7, column 15)

Posted by: raffriff42 Sep 25 2013, 08:53 PM
You didn't add quote marks around your file path, and you don't have a file extension
old:
V=AviSource (D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps)
new:
V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

Posted by: Virtualnoob123 Sep 25 2013, 08:53 PM
Ahh, that fixe it. Ok, now I go to compression tab?

Posted by: raffriff42 Sep 25 2013, 08:59 PM
Right. Not sure what "compression tab" you mean, but just make your final video as usual.

Posted by: Virtualnoob123 Sep 25 2013, 09:08 PM
Ok, so now I have the code working and can save the file.

I need to change the code to fit my video. It has 1859 frames and I have put the code like this:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

return UUChangeSpeed(Trim(V, 0, 500), 0)
\    + UUChangeSpeed(Trim(V, 500, 1000), 1.3)
\    + Trim(V, 1000, 1859, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


But I get errors like the last one.

I want to have normal speed up to 500 frames then from 500 to 1000 3 times faster. And from 1000 to the end of the video normal.

What do I need to do to get the code to work?

Posted by: raffriff42 Sep 25 2013, 09:15 PM
Trim runs to the end of the video when the second number is zero, so this
\ + Trim(V, 1000, 1859, 0)
should be
\ + Trim(V, 1000, 0)

Also: delete the first UUChangeSpeed for normal speed.
Also: if 1st part ends @ frame 500, next one starts @ 501
CODE
return Trim(V, 0, 500)
\    + UUChangeSpeed(Trim(V, 501, 1000), 1.3)
\    + Trim(V, 1001, 0)

Posted by: Virtualnoob123 Sep 25 2013, 09:23 PM
Ok, this seems to work just fine now:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

return UUChangeSpeed(Trim(V, 0, 500), 1)
\    + UUChangeSpeed(Trim(V, 501, 1000), 4)
\    + Trim(V, 1000, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


But for some reason instead of being 4 speed from 501-1000 frames it goes back to normal at around 600-650 frames. And stays normal speed to the end of the video.


Posted by: raffriff42 Sep 25 2013, 09:23 PM
QUOTE (Virtualnoob123 @ Sep 25 2013, 09:23 PM)
Ok, this seems to work just fine now:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

return UUChangeSpeed(Trim(V, 0, 500), 1)
\    + UUChangeSpeed(Trim(V, 501, 1000), 4)
\    + Trim(V, 1000, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


But for some reason instead of being 4 speed from 501-1000 frames it goes back to normal at around 600-650 frames.  And stays normal speed to the end of the video.

That's because frames were removed to speed up the video. cool.gif

Posted by: Virtualnoob123 Sep 25 2013, 09:26 PM
I added that piece of code to mine like this:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

return Trim(V, 0, 500)
\    + UUChangeSpeed(Trim(V, 501, 1000), 4)
\    + Trim(V, 1001, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


And got the same resaults. Goes back to normal speed at around 600-650!

Posted by: raffriff42 Sep 25 2013, 09:33 PM
OK this change to the code will show what's happening with the source frames.
As mentioned in the comment, when done debugging, add a "#" in front of the "ShowFrameNumber" line to disable it
CODE
#avisynth

V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

## debugging: show the original frame number from the source video
## (when done debugging, add a "#" in front of this line to disable it)
V=V.ShowFrameNumber()

return UUChangeSpeed(Trim(V, 0, 500), 1)
\    + UUChangeSpeed(Trim(V, 501, 1000), 4)
\    + Trim(V, 1000, 0)

function UUChangeSpeed(clip c, float factor)
{
oldRate = FrameRate(c)
newVid = AssumeFPS(c, oldRate * factor)
return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}

Posted by: Virtualnoob123 Sep 25 2013, 09:34 PM
QUOTE (raffriff42 @ Sep 25 2013, 09:23 PM)
QUOTE (Virtualnoob123 @ Sep 25 2013, 09:23 PM)
Ok, this seems to work just fine now:

CODE

#avisynth
## speed change test:
##   half speed from frame 0 to frame 29;
##   130% speed from frame 30 to frame 149
##   normal speed to end of video

V=AviSource ("D:\Movie Folder\Kharg Island\Scout vs stinger noob 45fps.avi")

return UUChangeSpeed(Trim(V, 0, 500), 1)
\    + UUChangeSpeed(Trim(V, 501, 1000), 4)
\    + Trim(V, 1000, 0)

function UUChangeSpeed(clip c, float factor)
{
 oldRate = FrameRate(c)
 newVid = AssumeFPS(c, oldRate * factor)
 return AudioDub(ChangeFPS(newVid, c), c.TimeStretch(tempo=100*factor))
}


But for some reason instead of being 4 speed from 501-1000 frames it goes back to normal at around 600-650 frames.  And stays normal speed to the end of the video.

That's because frames were removed to speed up the video. cool.gif

Well, how do I get the video to speed up from frame 501-1001 and not drop off 400 frames too early?! biggrin.gif

Posted by: raffriff42 Sep 25 2013, 09:49 PM
Just watch the video, it works I promise you. I guess I fail at explaining.

Posted by: Virtualnoob123 Sep 25 2013, 09:59 PM
QUOTE (raffriff42 @ Sep 25 2013, 09:49 PM)
Just watch the video, it works I promise you. I guess I fail at explaining.

Yes, you have solved my problem and thanks.

It's just I want to stop the speeded up section on frame 1000, but it drops off at 650. Guess I just add 450 frames to the code.






Posted by: meowmeow Sep 27 2013, 03:17 PM
Thanks! Nice, nice code works with both video & audio only. And those frames which lost - they're lost while maintaining same FPS at shorter time.

Posted by: malky Sep 28 2013, 10:13 AM
Great code.Much easier solution than mine.

http://forums.virtualdub.org/index.php?act=ST&f=2&t=21264&hl=virtualdub

Posted by: raffriff42 Sep 28 2013, 10:43 PM
Thanks. I should really credit http://forums.somethingawful.com/showthread.php?threadid=3486018&pagenumber=94&perpage=40#post417244438 (I think it was this one) for the idea.

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