View Full Version : Speeding up video while keeping audio pitch the same
EpheMeroN
28th January 2012, 20:28
My girlfriend needs to use a 6 minute YouTube video for a presentation for her class. The problem is, they are limited to using 4 minutes worth of video content.
Is there a way w/ AviSynth to speed up the video to make it fit within a 4 minute duration while keeping the audio pitch the same? I don't want to speed it up and have the narrator sound like a chipmunk.
Gavino
28th January 2012, 20:49
http://avisynth.org/mediawiki/TimeStretch
EpheMeroN
28th January 2012, 20:57
But how would I script this so that the video and audio match up? I haven't used AviSynth in quite some time.
I could get FFMPEGSource2 so import the FLV file, but I found "Pazera Free FLV to AVI Converter" which was able to decode the FLV to an uncompressed Huffyuv AVI file. Now I can import the video wherever, but I'd rather just do it all within a script.
IanB
28th January 2012, 21:48
...
AssumeScaledFPS(6, 4, False) # Run video 6/4 faster
TimeStretch(Pitch=100.0*4.0/6.0, Rate=100.0*6.0/4.0) # Set pitch and rate back to normal
...
Edit: Of course could have just used TimeStretch(Tempo=100.0*6.0/4.0) instead of futzing around with pitch and rate. Doh!
ajp_anton
29th January 2012, 15:58
If AssumeScaledFPS(...,..., True) already syncs the audio (with a different pitch), why touch the Rate in TimeStretch?
And wouldn't it be better to adjust the audio in a single step within TimeStretch? Maybe it doesn't matter much, but it feels like the precision would be higher.
AssumeScaledFPS(6, 4, False) #speed up video
TimeStretch(Rate=100.0*6.0/4.0) #speed up audio
Gavino
29th January 2012, 19:32
Actually, you're both wrong!
The rate parameter in TimeStretch() doesn't actually change the sampling rate, it changes both pitch and tempo together.
In IanB's solution, his AssumeScaledFPS() increases both the pitch and the sampling rate by 50%, while his TimeStretch() has the overall effect of maintaining that increased pitch and sampling rate while increasing the tempo by a further 50% (and losing audio sync).
ajp_anton's solution keeps the original sampling rate and maintains audio sync with the faster video, but not the pitch which is raised by 50%.
The following code works to speed up both video and audio in sync, maintaining the original sampling rate and pitch:
AssumeScaledFPS(6, 4) # Run video 6/4 faster
TimeStretch(tempo=100.0*6.0/4.0) # Run audio 6/4 faster, maintaining pitch
Like the previous versions, this changes the video frame rate (increasing it by 50%).
If it is desired to keep the original frame rate (probably better for YouTube), you can replace the AssumeScaledFPS() line by:
ChangeFPS(4*FrameRateNumerator(), 6*FrameRateDenominator()).AssumeFPS(last)
ajp_anton
29th January 2012, 23:44
Ah yes, I confused Rate and Tempo. Could've just checked one of my speedup functions to see that it uses Tempo, but I was sure it was Rate so I went with that =).
edit:
Oh, and for same-framerate output, I would use the following (even though the result is probably the same):
AssumeScaledFPS(6, 4).ChangeFPS(last)
Gavino
30th January 2012, 00:46
Oh, and for same-framerate output, I would use the following (even though the result is probably the same):
AssumeScaledFPS(6, 4).ChangeFPS(last)
I agree, that's a nicer way of writing it.
IanB
30th January 2012, 23:42
Opps I stuffed the audio sample rate, should have been false, post fixed. :o
AssumeScaledFPS(6, 4, False).ChangeFPS(last) converts the video FPS back by dropping 33% of the frames. Given it's a 50% speed up this is probably okay. If motion mattered then maybe some MVTools magic might be in order.
Note: If this was an interlaced project you might want to smart bob it to a double rate stream then zap 33% of those frames and then re-interlace.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.