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 21st June 2017, 17:35   #21  |  Link
srfscenar
Registered User
 
Join Date: May 2003
Posts: 492
Quote:
Originally Posted by real.finder View Post
Code:
AssumeFPS(24, sync_audio=true).SSRC(AudioRate())
Code:
AssumeFPS(24000, 1001, sync_audio=true).SSRC(AudioRate())
can do what the Thread talk about
Sorry, I am not that into code!
Is that an avs script? Is there a simple math that gives the required tempo?

I want to use the soundstretch command line (soundstretch.exe 'IN' 'OUT' -tempo=xxxxx
I want to calculate that xxxx when going from 25fps to 24 or 23.976.

Any ideas?

Thanks!
__________________
" 2 minds are better than 1 "

Last edited by srfscenar; 21st June 2017 at 17:42.
srfscenar is offline   Reply With Quote
Old 21st June 2017, 19:41   #22  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,981
Is this what you seek (near bottom of page):- http://avisynth.nl/index.php/TimeStretch

Code:
     Raise playback tempo from NTSC Film speed (23.97 fps) to PAL speed (25 fps) without changing pitch: 

TimeStretch(tempo=100.0*25.0/(24000.0/1001.0))
which looks like for slowdown maybe something like

Code:
     Lower playback tempo from PAL speed (25 fps) to NTSC Film speed (23.97 fps) without changing pitch: 

TimeStretch(tempo=100.0*(24000.0/1001.0)/25.0)
#  or TimeStretch(tempo=4.0*(24000.0/1001.0))
#  or TimeStretch(tempo=4.0*24000.0/1001.0)
#  or TimeStretch(tempo=96000.0/1001.0)
For 25 -> 24FPS slowdown
Code:
     Lower playback tempo from PAL speed (25 fps) to Film speed (24.0 fps) without changing pitch: 

TimeStretch(tempo=100.0*24.0/25.0)
#  or TimeStretch(tempo=4.0*24.0)
#  or TimeStretch(tempo=96.0)
where tempo = 96% = (100%-96%) = 4% slowdown. (24.0/25.0=0.96)

EDIT: This seems to work OK (result as Percent, dont know what SoundStretch.Exe expects)
Code:
Function TimeStretchTempo(clip InC,Float OutNum,Float "OutDen") { 
    # http://forum.doom9.org/showthread.ph...35#post1810135
    # Returns Timestretch() Tempo arg, to change playback tempo when changing VideoFramerate, without changing pitch: 
    Num    = InC.FrameRateNumerator      
    Den    = InC.FrameRateDenominator
    OutDen = Default(OutDen,1.0).Float
    Assert(0.0<OutNum,String(OutNum,"TempoAsPercent: 0.0 < OutNum(%f)"))
    Assert(0.0<OutDen,String(OutDen,"TempoAsPercent: 0.0 < OutDen(%f)"))
    Return 100.0 * OutNum * Den / (OutDen * Num)               # All are Coerced to Float (v2.58 Incl)    
}


InC=ColorBars
IFPS=25.0
InC=InC.AssumeFPS(IFPS)                                        # Input simulated FPS : Audio No Change

ONUM=24000
ODEN=1001

Tempo=InC.TimeStretchTempo(ONUM,ODEN)                          # Calc Required Tempo keeping same pitch as InC

OutAudio=InC.TimeStretch(tempo=Tempo).ResampleAudio(InC.AudioRate)   # Stretch and back to Original SampleRate
                                                               # SSRC() can fail with some ratios, 
                                                               # ResampleAudio() almost no differt to SSRC() for some years.
                                                               
OutC=InC.AssumeFPS(ONUM,ODEN,Sync_Audio=False)                 # Output Video rate leaving Audio as was

Last=OutC.AudioDub(Outaudio)                                   # Result Explicit assign to Last (no reason)

RT_Subtitle("InFPS=%f : OutFPS=%f : Tempo=%f%%",InC.FrameRate,FrameRate,Tempo)
EDIT: Oops, changed TimeStretch(Tempo) to TimeStretch(tempo=Tempo) : EDIT: Tempo 1st arg after clip anyway so was no prob.

EDIT: Links in CODE blocks no longer seems to work automatically.

EDIT: Function re-named as per following my post.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 22nd June 2017 at 00:25.
StainlessS is offline   Reply With Quote
Old 21st June 2017, 21:05   #23  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,589
Quote:
Originally Posted by srfscenar View Post
Sorry, I am not that into code!
Is that an avs script? Is there a simple math that gives the required tempo?

I want to use the soundstretch command line (soundstretch.exe 'IN' 'OUT' -tempo=xxxxx
I want to calculate that xxxx when going from 25fps to 24 or 23.976.

Any ideas?

Thanks!
it's avs of course

With it you can change the speed of video and audio (with pitch change)
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 21st June 2017, 21:16   #24  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 7,019
tempo = 100 * ( FpsOUT/FpsIN - 1 )

eac3to "25" -stdout.wav -simple | soundstretch stdin 23.976.wav -tempo=-4.095904
eac3to "23.976" -stdout.wav -simple | soundstretch stdin 25.wav -tempo=4.2708333

eac3to "25" -stdout.wav -simple | soundstretch stdin 24.wav -tempo=-4.0
eac3to "24" -stdout.wav -simple | soundstretch stdin 25.wav -tempo=4.1666667

eac3to "24" -stdout.wav -simple | soundstretch stdin 23.976.wav -tempo=-0,0999001
eac3to "23.976" -stdout.wav -simple | soundstretch stdin 24.wav -tempo=0.1
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 21st June 2017, 22:46   #25  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,981
Thank you Tebasuna51.

I presume that Soundstretch can somehow be called from inside Avisynth (otherwise what is it doing in this forum), so ... [EDIT: at least via RT_Call/CallCmd]

Added SoundStretch version of Tempo as SoundStretchTempo() (relative to 100.0%)
Code:
Function TimeStretchTempo(clip InC,Float OutNum,Float "OutDen") { 
    # https://forum.doom9.org/showthread.p...35#post1810135
    # Returns Timestretch() Tempo arg, to change playback tempo when changing Video Framerate, without changing pitch: 
    Num    = InC.FrameRateNumerator      
    Den    = InC.FrameRateDenominator
    OutDen = Default(OutDen,1.0).Float
    Assert(0.0<OutNum,String(OutNum,"TempoAsPercent: 0.0 < OutNum(%f)"))
    Assert(0.0<OutDen,String(OutDen,"TempoAsPercent: 0.0 < OutDen(%f)"))
    Return 100.0 * OutNum * Den / (OutDen * Num)               # All are Coerced to Float (v2.58 Incl)    
}


Function SoundStretchTempo(clip InC,Float OutNum,Float "OutDen") { 
    # Returns SoundStretch() Tempo arg, to change playback tempo when changing Video Framerate, without changing pitch:
    Return TimeStretchTempo(InC,OutNum,OutDen) - 100.0 
}

Function CmpTempo(clip c,Float IFPS,Float OutNum,Float "OutDen") {
    c.AssumeFPS(IFPS)                                           # Input simulated FPS : Audio No Change
    TST=TimeStretchTempo(OutNum,OutDen)
    SST=soundStretchTempo(OutNum,OutDen)
    OutDen = Default(OutDen,1.0).Float
    Return RT_String("InFPS=%.3f : OutFPS=%.3f : TimeStretchTempo=%10.6f%% : SoundStretchTempo=%10.6f%%\n",FrameRate,OutNum/OutDen,TST,SST)
}

ColorBars(Width=960)
GSCript("""
    S=""
    for(i=0,5) {# 0)=25.0->23.976 : 1)=23.976->25.0 : 2)=25.0->24.0 : 3)=24.0->25.0 : 4)=24.0->23.976 : 5)=23.976->24.0
        IFPS = Select(i,   25.0, 23.976,  25.0,  24.0,  24.0,  23.976)
        ONUM = Select(i,  24000,     25,    24,    25, 24000,      24)
        ODEN = Select(i,   1001,      1,     1,     1,  1001,       1)
        S = S + CmpTempo(Last,IFPS,ONUM,ODEN)    
    }
    RT_DebugF("%s",S)
    RT_Subtitle("%s",S)
""")
Return Last
Results from DebugView
Code:
00000003    1.71319640  [4984] RT_DebugF: InFPS=25.000 : OutFPS=23.976 : TimeStretchTempo= 95.904099% : SoundStretchTempo= -4.095901%   
00000004    1.71322191  [4984] RT_DebugF: InFPS=23.976 : OutFPS=25.000 : TimeStretchTempo=104.270935% : SoundStretchTempo=  4.270935%   
00000005    1.71325016  [4984] RT_DebugF: InFPS=25.000 : OutFPS=24.000 : TimeStretchTempo= 96.000000% : SoundStretchTempo= -4.000000%   
00000006    1.71327806  [4984] RT_DebugF: InFPS=24.000 : OutFPS=25.000 : TimeStretchTempo=104.166664% : SoundStretchTempo=  4.166664%   
00000007    1.71330607  [4984] RT_DebugF: InFPS=24.000 : OutFPS=23.976 : TimeStretchTempo= 99.900101% : SoundStretchTempo= -0.099899%   
00000008    1.71333420  [4984] RT_DebugF: InFPS=23.976 : OutFPS=24.000 : TimeStretchTempo=100.100098% : SoundStretchTempo=  0.100098%
EDIT: Made SoundStretchTempo() a stub calling TimeStretchTempo().

EDIT: As well as forum now not automatically adding links in CODE blocks, also now messes up links when editing post containing a previously good link
(in a CODE block). (you get a 404 NOT FOUND page, This is a Serious Problem and will not get better in time if not fixed)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 22nd June 2017 at 19:36.
StainlessS is offline   Reply With Quote
Old 22nd June 2017, 12:28   #26  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 7,019
Quote:
Originally Posted by StainlessS View Post
I presume that Soundstretch can somehow be called from inside Avisynth (otherwise what is it doing in this forum), so ...
I put comand line options because:

Quote:
Originally Posted by kuchikirukia View Post
Can't eac3to do this in one command?
And seems srfscenar want also these command lines.

BTW:
Quote:
Originally Posted by tebasuna51 View Post
The AviSynth plugin TimeStretch are based in SoundTouch libraries and there are a command line tool (SoundStretch 1.9.2 for Windows) that can be used with eac3to:...
Then avs TimeStretch (latest version) is the same than Soundstretch Command Line.

Not need more avs functions.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 22nd June 2017, 13:08   #27  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,981
Quote:
Originally Posted by tebasuna51 View Post
The AviSynth plugin TimeStretch are based in SoundTouch libraries and there are a command line tool (SoundStretch 1.9.2 for Windows) that can be used with eac3to:...

Then avs TimeStretch (latest version) is the same than Soundstretch Command Line.
Good to know, thanks.

Quote:
Originally Posted by tebasuna51 View Post
Not need more avs functions.
I'll just leave as it is, example just shows the difference between TimeStretch relative 0.0% Tempo and SoundStretch relative 100.0% Tempo.

EDIT:
ie,
Code:
TimeStretch_Tempo  = 100 * ( Float(FpsOUT)/FpsIN )
SoundStretch_Tempo = 100 * ( Float(FpsOUT)/FpsIN - 1 ) # or SoundStretch_Tempo = TimeStretch_Tempo - 100.0
EDIT:
Had not previously tested output, 25.0 -> 12.5 FPS, works fine, same audio length, and in-sync (vlong clips may lose sync).
(but sounds a bit echo-y [well waddya expect @ half rate ].
Code:
#Import("TimeStretchTempo.avs")
Avisource("D:\v\XMen2.avi").Trim(10000,-10000) # 25.0 FPS PAL
ORATE=FrameRate / 2.0 # Half Input rate, extreme test
Return AudioDub(Assumefps(ORATE),TimeStretch(Tempo=TimeStretchTempo(ORATE)).ResampleAudio(Audiorate))
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 22nd June 2017 at 14:19.
StainlessS is offline   Reply With Quote
Old 22nd June 2017, 13:34   #28  |  Link
srfscenar
Registered User
 
Join Date: May 2003
Posts: 492
tebasuna51 and StainlessS thank you very much! Exactly what I needed!
Thanks!
__________________
" 2 minds are better than 1 "
srfscenar is offline   Reply With Quote
Reply

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 14:25.


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