-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SaveFrames() misses some frames #5685
Comments
My diagnosis and Understanding : In the implementation of Line 455 in 4b36461
Let's focus on key arguments here, that is
if the duration is 1 sec and fps is 25 that essentially means 1*25 frames should be recorded. scrolling down, we can encounter the following two parts PART 1 const frameFactory = setInterval(() => {
frames.push(makeFrame(fName + count, ext, cnv));
count++;
}, 1000 / fps);
PART 2 setTimeout(() => {
clearInterval(frameFactory);
if (callback) {
callback(frames);
} else {
for (const f of frames) {
p5.prototype.downloadFile(f.imageData, f.filename, f.ext);
}
}
frames = []; // clear frames
}, duration + 0.01);
}; I think the problem lies in PART 2, setTimeout stops the setInterval exactly after duration which is not the correct way, because the work of PART 1 may not necessarily get completed after the given duration because making frame every time requires some work and hence some time which may not be essentially instant. I think the implementation should be like this totalRequiredFrames = fps*duration; // new code line
const frameFactory = setInterval(() => {
frames.push(makeFrame(fName + count, ext, cnv));
count++;
// new code line
if(count > totalRequiredFrames){
clearInterval(frameFactory);
}
}, 1000 / fps); |
I get the exact same behaviour. I would love to know from the team what are the exact intentions behind this function: if it was actually meant to save an arbitrary number of frames for a given animation and that means this is a bug, or if, on the other hand, there was a deliberate decision on capping the number of frames being processed so the sketch does not get blocked if there is a lot to process in a particularly busy sketch. Can you help or guide us, @stalgiag? Or know someone that can? |
@endurance21 What's happening is actually much simpler than that, p5.js limits the maximum frame rate to 22 and the maximum duration to 15, any values outside of this range will be clamped back down to 22 and 15. It isn't made very clear in the documentation and I think we should clarify it better. @jesi-rgb As alluded to in the reference, |
@limzykenneth gotcha! everything clear! we can actually change that real quick in the docs! |
Most appropriate sub-area of p5.js?
p5.js version
v1.4.1
Web browser and version
Google Chrome 102.0.5005.61
Operating System
Mac OS
Steps to reproduce this
Steps:
Snippet:
The text was updated successfully, but these errors were encountered: