Animation Sync Problem

Hi everyone, i’m not quite sure if it is the right section for posting it, but i’ve got this problem:

  • I’m rendering/compositing an audio driven animation over a video and his music
  • The video frame rate is 29 fps and is loaded in blender with the movieclip compositing node
  • The music is imported as movie in VSE and the corresponding video part is removed leaving only the song
  • The closet frame rate i can set in blender is 29.97

That said, as result i’ve got the video/audio portion going well together and the overlayed rendered animation out of sync (shorter to be precise).

Please help me, my brain is twisting.

After proper thinking moments i realized that there is a workaround to avoid this problem:

  • Because Blender process the music to drive the animation in a faster fashion (due to the mismatch 29.97 Fps > 29 Fps), the resulting animation is shorter than the audio and video themselves. In other words the Fps mismatch causes an Out of Sync issue.

  • To avoid this, the driving song speed can be reduced by the same amount that is automatically increased by Blender.

The slowing process can be done for example in Matlab, Scilab and Octave to name a few. With the former option the task is accomplished by using the following code:

%%% MATLAB CODE STARTS HERE!! :):slight_smile:
%%% This script is used to load the song in the Matlab workspace to apply
%%% resampling based on the input media frame rate and the blender choosen
%%% frame rate, then the processed audio is saved.
%%% The resampling is accomplished avoiding initial and final filtering
%%% transient.
%%% THe all process uses one audio channel only (Mono)
% script fresh start
clear all;close all;clc
% audio file import
filename = ‘i 30 sec’; % put here your file name!
typ = ‘.mp3’; % put here the file extension!
[DataStereo,Fs] = audioread([filename,typ]);
DataMono = mean(DataStereo’);
% choose resample parameters based on media Fps and Blender Fps
BFps = 2997; % Blender Fps value multipliedby 100 to make it integer
MFps = 2900; % Video Fps value used for animation
% <Note>: if you multiply one of the two values you must do
% the same thing to the other value, because the resample
% function thakes into account the ratio: “Ratio = BFps/MFps”
Ratio = BFps/MFps;

% header and tail creation + connection
Tap = 20;
for k = 1:Tap
head(1+Tap-k) = 2DataMono(1)-DataMono(k);
tail(k) = 2
DataMono(end)-DataMono(end-k);
end
temp1 = [head,DataMono,tail];
% resampling + header and tail removal
temp2 = resample(temp1,BFps,MFps);
ResampledData = temp2(floor(RatioTap)+1:end-ceil(RatioTap));
% comparison
figure;
subplot(2,1,1)
plot(DataMono,‘b’)
xlim([1,length(DataMono)])
ylim([-1.1,1.1])
title(‘Input Mono Sound Samples’)
subplot(2,1,2)
plot(ResampledData,‘r’)
xlim([1,length(ResampledData)])
ylim([-1.1,1.1])
title(‘Resampled Mono Sound Samples’)
% listening comparison between the input sound samples and the resampled
% one. As long that Ratio is close enough to unity, the prefilter used in resample do not
% change things significcantly, so the two samples should be heard without noticeable difference
if 1
disp(‘play: Input Sound Samples’)
sound(DataMono,Fs)
disp(‘play: Resampled Sound Samples at Blender Speed’)
sound(ResampledData,Fs*Ratio)
end
% the resampled track is then saved in a “.wav”
audiowrite([filename,’_resample.wav’],ResampledData,Fs)

%%% END OF CODE

Now it all works fine, PROBLEM SOLVED(avoided, workarounded, headaches, programming fun).

Hope it can be usefull to other peoples with the same issue.

Select Custom in the pulldown menu for the frame rate settings to appear.


Setting to exact 29 still causes out of synch problems over time. Tha’s why i use the workaround, thank you anyway :slight_smile: