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. |
|
26th June 2017, 21:40 | #1 | Link |
Guest
Posts: n/a
|
Stretching Audio: N+1,2,3,etc Frames in AviSynth
I wonder if it's possible to stretch a section of audio and video so that it occupies the same number of frames as the original +1,2,3 etc. The important thing is for the audio to be stretched in as high a quality method as possible so that it occupies its new length; the video can make up the difference by adding duplicates (as long as it is returned in sync along with the audio). At present, I approximate the effect that I want by trimming out a section and doing the following.
Code:
#Assuming a 23.976fps A/V source... Trim() ChangeFPS(25000,1001) AssumeFPS(24000,1001, sync_audio=true) SSRC(48000)# or ResampleAudio(48000) or whatever |
26th June 2017, 23:05 | #2 | Link |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
For syncing audio and video it is always best to leave the video length alone (i.e., don't duplicate or decimate frames). The audio can be shortened or lengthened by quite a bit, without changing pitch, and without a noticeable hit in quality, if you use high-quality audio software. I use Vegas Pro, and once I've changed the audio length, I make sure that Vegas is using the "Elastique" plugin, which produces infinitely superior quality to the stretching plugin that originally shipped with that product.
|
26th June 2017, 23:20 | #3 | Link |
Guest
Posts: n/a
|
Thanks, johnmeyer! But I was hoping for an AviSynth-based solution if possible. :-)
In respect of the video, I agree with you. The reason that I'm stretching the video here is that it's a way of making AssumeFPS()'s sync_audio=true parameter do something it's probably not meant to do, and adding/dropping frames just helps me to visualize what's going on and has no effect on my output. Doing unorthodox things in AviSynth is something of a hobby of mine. |
26th June 2017, 23:47 | #4 | Link |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
I've done a lot of tests for people, where they provide the audio clip and then various people stretch it. I don't remember AVISynth having a really good audio stretch plugin, especially when the result is compared to what the more professional, non-AVISynth software can do.
|
27th June 2017, 00:37 | #6 | Link |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
you can use timestretch() . The quality actually isn't that bad
http://avisynth.nl/index.php/TimeStretch I hardcoded this example for 90% speed, for some reason you can't use variables to calculate in the changefps field, but the value would be 100/90 or 100/value , where value is expressed in percentage you can check with info that the new a/v length is the same (or very close) Code:
#Assuming a 23.976fps A/V source... whateversource() trim() timestretch(tempo=90) changefps(1.111111*last.framerate) assumefps(24000,1001) #info() Code:
#Assuming a 23.976fps A/V source... p=90 #in percent m=(100/p) whateversource() trim() timestretch(tempo=90) changefps(m*last.framerate) assumefps(24000,1001) #info() Last edited by poisondeathray; 27th June 2017 at 00:40. |
27th June 2017, 07:43 | #7 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Try this ... Code:
m = 100.0/p |
|
27th June 2017, 15:28 | #8 | Link | ||
Registered User
Join Date: Sep 2007
Posts: 5,377
|
Quote:
Quote:
|
||
27th June 2017, 15:16 | #9 | Link | |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
|
Quote:
If you want a newer TimeStretch version which is not restricted to stereo you can either download Wilbert's TimeStretch plugin https://forum.doom9.org/showpost.php...2&postcount=20 or use the latest AviSynth v2.61 Alpha version which features an even newer version... Cheers manolito |
|
27th June 2017, 11:05 | #11 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Code:
n = 1 # or 2, 3, ... (no of frames to add) whateversource() trim(...) fc = Framecount() m = float(fc+n)/fc timestretch(tempo=100/m) changefps(m*last.framerate) assumefps(24000,1001) |
|
27th June 2017, 15:13 | #12 | Link |
Guest
Posts: n/a
|
^ Thanks! I have two problems though.
First, I don't know how to adapt the above to a script in which a clip is already defined. Obviously, in your example, everything is being assigned to last. Normally, I would do something like... Code:
s1=WhateverSource() Trim(s1,x,y).Whatever().Whatever() Secondly, if I change n to one, the above doesn't seem to be increasing the number of frames by one. I'm not sure why. Code:
m = float(fc+1)/fc Last edited by Richard1485; 22nd November 2018 at 19:30. Reason: clarification |
27th June 2017, 15:24 | #13 | Link | |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
Quote:
Probably because of implicit "last" You can specify exactly what you're referring to (eg. which framecount, the original, cuta , cutb, etc...) here a1 is defined as segment (1000-2000), and that is what the framecount refers to, not original or some other cut. You would do that for each section you're trying to stretch to keep it organized Code:
orig=last n=4 a1=orig.trim(1000,2000) fc = a1.Framecount() m = float(fc+n)/fc a1 timestretch(tempo=100/m) changefps(m*last.framerate) assumefps(24000,1001) |
|
27th June 2017, 23:04 | #14 | Link | |
Guest
Posts: n/a
|
Quote:
|
|
27th June 2017, 15:29 | #15 | Link |
Guest
Posts: n/a
|
^^^ Thanks, manolito! I was wondering about that. My clip is dual mono, so I was wondering if I have to process the channels separately with 2.60 or just discard one before applying TimeStretch() and then call MonoToStereo() afterwards.
@Gavino I've managed to get it working like this. Code:
clip=AviSource("s.avi",audio=true) clip2=Trim(clip, 40430, 40451) fc = Framecount(clip2) m = float(fc+1)/fc clip3= \ clip2 \ .TimeStretch(tempo=100/m) \ .ChangeFPS(m*clip2.framerate) \ .assumeFPS(24000,1001) return clip3 EDIT: Sorry, pdr. I was typing while you were posting and didn't see your replies. Last edited by Richard1485; 27th June 2017 at 15:36. |
27th June 2017, 16:31 | #16 | Link |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
I know the OP wants to use AVISynth, but it is actually a lousy tool for this particular problem. Why? Because you can't set the values simply by interacting with a GUI display of the audio on a timeline. Doing what the OP wants would take me just a few seconds in my NLE (Vegas):
1. Put the video on one track, and the audio on the track below. 2. Sync the audio and video at the beginning of the track. 3. Go to the end of the track, grab the edge of the end of the audio clip, hold the Ctrl key (to force the audio to stretch), and drag the audio until it syncs with the video. If you already have another track that is synced to the video (i.e., lousy audio, but synced to the video), you can do this all by looking at the waveforms, and it is almost instantaneous. To get a really good sync, you have to find places where people are talking, in close-up, and find a place where they say something with a "p" or "m" or other syllable where the lips come together. You then sync on these points. You do it at the beginning and the end of the clip, and follow my 1-2-3 instructions above. I have no idea in the world how you are going to do that by plugging numbers into an AVISynth script, rendering out a result and then trying it out. It is going to take hours instead of seconds. So, as I've said in other threads on this same subject, AVISynth is not the right tool for this project. Last edited by johnmeyer; 27th June 2017 at 16:32. Reason: clarity |
27th June 2017, 19:07 | #17 | Link |
Guest
Posts: n/a
|
^ Yes, you have said that many times. This thread is about syncing in AviSynth, and it's located in the AviSynth forum. You might have "no idea in the world" how I'm going to sync in AviSynth, but I know perfectly well what I'm doing and have been syncing tracks in a similar fashion for years; it will certainly not take me hours, and no rendering apart from the final render is required. This is the third time that I have responded (politely) to a post of yours in a similar vein, and I'd rather not do so again. I appreciate that you have a different approach, and you're welcome to it, but please start a new thread if you want to keep talking about doing this in Vegas.
|
27th June 2017, 21:55 | #18 | Link | |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
Quote:
Good luck with your project. You obviously know what you are doing. Last edited by johnmeyer; 27th June 2017 at 21:55. Reason: typo |
|
22nd November 2018, 19:48 | #19 | Link |
Guest
Posts: n/a
|
Upon reflection, when splicing a stretched section back into the "timeline", there are audible pops. At first, I thought it was because I was setting n to -1, but it's the same when it is set to 1. Perhaps, it's because the stretched audio doesn't quite match the length of the video.
Any suggestions would be appreciated. I know it's been a while. |
Tags |
audio, avisynth, stretch |
|
|