I am using java to create image files that I am converting to video using FFMPEG. I am creating the midi and audio simultaneously on reaper then using the duration of the notes on the midi file to create the number of frames I need. These are the durations of the different notes I have:
306.1224966434529 612.2449932869058 1224.4899865738262 1836.734979860732
In order to get the frames I need I am using the formula (fps * duration) / 1000 then rounding down which results in:
306.1224966434529 -> 18 frames 612.2449932869058 -> 36 frames 1224.4899865738262 -> 72 frames 1836.734979860732 -> 110 frames
When I combine the audio it gradually goes out of sync. I played around and realised that the 72 frames require 74 frames and the 110 frame notes require 112 frames.
I am not sure how to account for this. I need to be able to calculate the number of frames required ahead of time rather than creating them in real time.