AssumeSampleRate
From Avisynth wiki
(Difference between revisions)
Raffriff42 (Talk | contribs) (add example) |
(add link to avs+ documentation) |
||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
+ | |||
+ | <div {{BlueBox2|40|0|3px solid purple}} > | ||
+ | {{AvsPlusFullname}}<br> | ||
+ | Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/assumerate.html https://avisynthplus.readthedocs.io] | ||
+ | </div> | ||
+ | |||
+ | |||
{{Template:FuncDef|AssumeSampleRate(clip ''clip'', int ''samplerate'')}} | {{Template:FuncDef|AssumeSampleRate(clip ''clip'', int ''samplerate'')}} | ||
Changes the sample rate of the current clip without changing the number of samples. | 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. | + | :This changes the sample rate, pitch, playback speed and running time of the audio. |
:It will also affect synchronization with the video. | :It will also affect synchronization with the video. | ||
Line 10: | Line 17: | ||
[[AviSource]]("video_audio.avi") | [[AviSource]]("video_audio.avi") | ||
# Let's say that this clip loses audio sync: | # Let's say that this clip loses audio sync: | ||
− | # | + | # by the end, the audio is behind by 200 milliseconds. |
− | dur = | + | Ar = [[Clip_properties|AudioRate]] # original audio sample rate |
− | adj = -0.200 | + | dur = [[Clip_properties|AudioDuration]] # total duration in seconds |
− | + | adj = -0.200 # correction needed (decrease audio duration by 200 msec) | |
# Adjust audio duration: | # Adjust audio duration: | ||
'''AssumeSampleRate'''([[Internal_functions#Round|Round]](dur / (dur+adj) * Ar)) | '''AssumeSampleRate'''([[Internal_functions#Round|Round]](dur / (dur+adj) * Ar)) | ||
− | |||
− | |||
− | |||
− | |||
# Video and audio are now in sync. | # Video and audio are now in sync. | ||
+ | |||
+ | # (optional) restore original sample rate. | ||
+ | #[[ResampleAudio]](Ar) | ||
</div> | </div> | ||
Latest revision as of 04:24, 18 September 2022
AviSynth+
Up-to-date documentation: https://avisynthplus.readthedocs.io
AssumeSampleRate(clip clip, int samplerate)
Changes the sample rate of the current clip without changing the number of samples.
- This changes the sample rate, pitch, playback speed and running time of the audio.
- It will also affect synchronization with the video.
[edit] Examples
- Fix an audio sync problem:
AviSource("video_audio.avi") # Let's say that this clip loses audio sync: # by the end, the audio is behind by 200 milliseconds. Ar = AudioRate # original audio sample rate dur = AudioDuration # total duration in seconds adj = -0.200 # correction needed (decrease audio duration by 200 msec) # Adjust audio duration: AssumeSampleRate(Round(dur / (dur+adj) * Ar)) # Video and audio are now in sync. # (optional) restore original sample rate. #ResampleAudio(Ar)
- 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)
[edit] 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.