Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 28th January 2012, 20:28   #1  |  Link
EpheMeroN
EphMan
 
Join Date: May 2004
Posts: 737
Speeding up video while keeping audio pitch the same

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.
EpheMeroN is offline   Reply With Quote
Old 28th January 2012, 20:49   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
http://avisynth.org/mediawiki/TimeStretch
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 28th January 2012, 20:57   #3  |  Link
EpheMeroN
EphMan
 
Join Date: May 2004
Posts: 737
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.
EpheMeroN is offline   Reply With Quote
Old 28th January 2012, 21:48   #4  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Code:
...
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!

Last edited by IanB; 30th January 2012 at 23:22. Reason: Opps, set audio to 72000 Hz (should be False on Assum..)
IanB is offline   Reply With Quote
Old 29th January 2012, 15:58   #5  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
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
ajp_anton is offline   Reply With Quote
Old 29th January 2012, 19:32   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
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:
Code:
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:
Code:
ChangeFPS(4*FrameRateNumerator(), 6*FrameRateDenominator()).AssumeFPS(last)
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 29th January 2012 at 20:11. Reason: minor text changes
Gavino is offline   Reply With Quote
Old 29th January 2012, 23:44   #7  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
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)

Last edited by ajp_anton; 29th January 2012 at 23:49.
ajp_anton is offline   Reply With Quote
Old 30th January 2012, 00:46   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by ajp_anton View Post
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th January 2012, 23:42   #9  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Opps I stuffed the audio sample rate, should have been false, post fixed.


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.
IanB is offline   Reply With Quote
Reply

Tags
audio, pitch, retiming, speed, video

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:50.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.