AssumeSampleRate: Difference between revisions
From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs) formatting, links, phrasing |
Raffriff42 (talk | contribs) add example |
||
| Line 6: | Line 6: | ||
==== Examples ==== | ==== Examples ==== | ||
<div {{BoxWidthIndent| | * Fix an audio sync problem: | ||
<div {{BoxWidthIndent|56|1}} > | |||
[[AviSource]]("video_audio.avi") | [[AviSource]]("video_audio.avi") | ||
# Let's say that this clip loses audio sync: | |||
# after 55 minutes the audio is behind by 200 milliseconds. | |||
# Play video at half speed: | dur = 3300.0 # total duration in seconds (55 minutes x 60) | ||
adj = -0.200 # correction needed (decrease audio duration by 200 msec) | |||
Ar = [[Clip_properties|AudioRate]] # original audio sample rate | |||
# Adjust audio duration: | |||
'''AssumeSampleRate'''([[Internal_functions#Round|Round]](dur / (dur+adj) * Ar)) | |||
# Restore original sample rate while retaining new duration; | |||
# this step is may be skipped if you don't mind a slightly nonstandard sample rate. | |||
[[ResampleAudio]](Ar) | |||
# Video and audio are now in sync. | |||
</div> | |||
* Play video and audio at half speed: | |||
<div {{BoxWidthIndent|56|1}} > | |||
[[AviSource]]("video_audio.avi") | |||
# Play video at half speed: audio will be out of sync | |||
[[AssumeFPS]]([[Clip_properties|FrameRate]]/2) | [[AssumeFPS]]([[Clip_properties|FrameRate]]/2) | ||
# Play audio at half speed: | # Play audio at half speed: (pitch will be lowered by an [[wikipedia:Octave|octave]]) | ||
AssumeSampleRate([[Clip_properties|AudioRate]]/2) | '''AssumeSampleRate'''([[Clip_properties|AudioRate]]/2) | ||
# Video and audio are now in sync. | # Video and audio are now in sync. | ||
# Equivalent to calling [[AssumeFPS]](..., sync_audio=true) (see below) | |||
</div> | </div> | ||
Revision as of 23:52, 17 May 2016
AssumeSampleRate(clip clip, int samplerate)
Changes the sample rate of the current clip without changing the number of samples.
- This changes the pitch, playback speed and running time of the audio.
- It will also affect synchronization with the video.
Examples
- Fix an audio sync problem:
AviSource("video_audio.avi") # Let's say that this clip loses audio sync: # after 55 minutes the audio is behind by 200 milliseconds. dur = 3300.0 # total duration in seconds (55 minutes x 60) adj = -0.200 # correction needed (decrease audio duration by 200 msec) Ar = AudioRate # original audio sample rate # Adjust audio duration: AssumeSampleRate(Round(dur / (dur+adj) * Ar)) # Restore original sample rate while retaining new duration; # this step is may be skipped if you don't mind a slightly nonstandard sample rate. ResampleAudio(Ar) # Video and audio are now in sync.
- Play video and audio at half speed:
AviSource("video_audio.avi") # Play video at half speed: audio will be out of sync AssumeFPS(FrameRate/2) # Play audio at half speed: (pitch will be lowered by an octave) AssumeSampleRate(AudioRate/2) # Video and audio are now in sync. # Equivalent to calling AssumeFPS(..., sync_audio=true) (see below)
See Also
- AssumeFPS: sync_audio
- If true, the audio sample rate is changed by the same amount; the pitch of the resulting audio is shifted.
- If false (the default), the audio is unchanged; this means the audio will lose synchronization over time.