Selur
6th December 2025, 18:17
Cleaning up my desktop, I just found a script I started a few weeks ago, where I'm trying to come up with a way to visualize audio to figure out the audio delay of a file.
Here's what I came up with so far:
import misc
# https://github.com/Selur/VapoursynthScriptsInHybrid/blob/master/misc.py
# load audio
core.std.LoadPlugin(path="%FILTERPATH%/SourceFilter/BestSource/BestSource.dll")
# bs.AudioSource(string source[, int track = -1, int adjustdelay = -1, int threads = 0, bint enable_drefs = False, bint use_absolute_path = False, float drc_scale = 0, int cachemode = 1, string cachepath, int cachesize = 100, bint showprogress = True, maxdecoders = 0])
# adjustdelay: Adjust audio start time relative to a video track number. Pass -2 to disable and -1 to be relative to the first video track if one exists. Specifying a non-video track is equivalent to passing -2. Note that the offset is always relative to the first CPU-decodable frame in the stream meaning that it may not be the correct delay when hwmode and variableformat are used.
# see: https://github.com/vapoursynth/bestsource
audio = core.bs.AudioSource(source="%INPUTFILE%", track = -1, adjustdelay = -2)
delay_ms = 0 # Here you can set custom delay values
audio = misc.DelayAudio(audio, delay_ms=delay_ms)
# rendering of an analog oscilloscope to display audio waveforms
core.std.LoadPlugin(path="%FILTERPATH%/Support/faveworm.dll")
# https://gitlab.com/EleonoreMizo/faveworm
sweep = clip.fps_den / clip.fps_num # 1/fps
scope = core.fw.scope(clip=clip, audio=audio, mode=2, sweep=sweep, beam_size=8, y_gain=1.0, y_ofs=-0.3) # doubles the visual height of the waveform
# draw vertial line every 10ms
scope = misc.AddVerticalLines(scope, interval_ms=10, color=1.0)
# overlay scope on video and display multiple frames instead of just one
compareFrameCount = 3 # number of frame to show
clip = misc.Overlay(clip, scope, opacity=0.5)
clip = misc.ShowFramesAround(clip, count=compareFrameCount)
https://i.ibb.co/5W1Fxqjx/grafik.png (https://ibb.co/svgHJL1J)
Just wanted to share this:
a. in case someone has use for it.
b. to ask : Has someone a better way to do this or suggestions on how to improve this?
Cu Selur
Here's what I came up with so far:
import misc
# https://github.com/Selur/VapoursynthScriptsInHybrid/blob/master/misc.py
# load audio
core.std.LoadPlugin(path="%FILTERPATH%/SourceFilter/BestSource/BestSource.dll")
# bs.AudioSource(string source[, int track = -1, int adjustdelay = -1, int threads = 0, bint enable_drefs = False, bint use_absolute_path = False, float drc_scale = 0, int cachemode = 1, string cachepath, int cachesize = 100, bint showprogress = True, maxdecoders = 0])
# adjustdelay: Adjust audio start time relative to a video track number. Pass -2 to disable and -1 to be relative to the first video track if one exists. Specifying a non-video track is equivalent to passing -2. Note that the offset is always relative to the first CPU-decodable frame in the stream meaning that it may not be the correct delay when hwmode and variableformat are used.
# see: https://github.com/vapoursynth/bestsource
audio = core.bs.AudioSource(source="%INPUTFILE%", track = -1, adjustdelay = -2)
delay_ms = 0 # Here you can set custom delay values
audio = misc.DelayAudio(audio, delay_ms=delay_ms)
# rendering of an analog oscilloscope to display audio waveforms
core.std.LoadPlugin(path="%FILTERPATH%/Support/faveworm.dll")
# https://gitlab.com/EleonoreMizo/faveworm
sweep = clip.fps_den / clip.fps_num # 1/fps
scope = core.fw.scope(clip=clip, audio=audio, mode=2, sweep=sweep, beam_size=8, y_gain=1.0, y_ofs=-0.3) # doubles the visual height of the waveform
# draw vertial line every 10ms
scope = misc.AddVerticalLines(scope, interval_ms=10, color=1.0)
# overlay scope on video and display multiple frames instead of just one
compareFrameCount = 3 # number of frame to show
clip = misc.Overlay(clip, scope, opacity=0.5)
clip = misc.ShowFramesAround(clip, count=compareFrameCount)
https://i.ibb.co/5W1Fxqjx/grafik.png (https://ibb.co/svgHJL1J)
Just wanted to share this:
a. in case someone has use for it.
b. to ask : Has someone a better way to do this or suggestions on how to improve this?
Cu Selur