Log in

View Full Version : Change FPS so audio and video durations match?


ACSignal
22nd May 2022, 00:17
Hello experts,

I have an AVI file with audio out of sync due to a gradual drift during the capture.

In VirtualDub there is an option under Video menu to adjust FPS so that video and audio durations match. This fixes the audio out of sync problem.

IS there a way to do the same in AVISynth?

Another question: What about changing the sample rate instead of FPS. That should accomplish the same result.

I would need to find out what the sample rate should be in order to match the duration of the video and then just call AssumeSampleRate(clip clip, samplerate int) function with that sample rate.

But again, is there a script or a function that can calculate the correct sample rate.

TIA

Overdrive80
22nd May 2022, 12:22
Total milisecond audio out sync = T_out [ms] @samplerate_s1 (Hz)
Total milisecond audio in sync = T_in [ms] @samplerate_s2 (Hz)

s1/T_out = s2/T_in => s2 = s1·T_in/T_out

Example codes conversion audio:

PAL a NTSC: 48000*25/(24000/1001)= 50050 [Hz]

"SlowDown 25 -> 23.976" SSRC(50050).AssumeSampleRate(48000)
"SpeedUp 23.976 -> 25" AssumeSampleRate(50050).SSRC(48000)

However, I prefer to modify the framerate of the audio and not subject the audio to a destructive process.

I assume that virtualdub will make use of convertfps along with assumefps.

tebasuna51
22nd May 2022, 12:50
It is not recommended change video FPS because must be fixed standard values: ...,23.976,24,25,...
Also it is not recommended change the audio samplerate because also must be fixed standard values ...,44100,48000,...

But we have a internal AviSynth function to change the audio duration to match the video duration with:

VideoDuration = FrameCount/FrameRate
factor = 100.0*VideoDuration/AudioDuration

TimeStretch(tempo=factor)
or
TimeStretch(rate =factor)
where
■ tempo adjusts speed while maintaining the original pitch.
■ rate adjusts playback rate that affects both tempo and pitch at the same time.

the rate method is equivalent to SSRC().AssumeSampleRate showed before but SSRC don't work for any value, only for NTSC <-> PAL rate

Of course that not solve always async problems with bad captures.

ACSignal
22nd May 2022, 20:57
Thanks, this is exactly what I was looking for.

Losko
8th June 2022, 10:03
Naive question:
isn't this the same as extracting the audio and then fixing the audio track as (pseudo commands):
assumeSampleRate(50050)
resample(48000)
[for a 23.976 fps -> 25 fps conversion, for example]
?