Skip to content

Commit

Permalink
Add an option to speed up timelapse clips in video preview mode. Just…
Browse files Browse the repository at this point in the history
… turn dial up or down
  • Loading branch information
naixx committed Jun 11, 2024
1 parent 5688a55 commit 20c8a58
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
25 changes: 23 additions & 2 deletions hardware/oled.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ oled.exposure = function(jpegFile, textArray, highlightTextIndex) {
}
}

fb.font(MENU_STATUS_FONT_SIZE, false, FONT_DEFAULT);
fb.font(MENU_STATUS_FONT_SIZE, false, FONT_DEFAULT); fb.font(MENU_STATUS_FONT_SIZE, false, FONT_DEFAULT);
color("primary");
var sectionSize = 160 / textArray.length;
for(var i = 0; i < textArray.length; i++) {
Expand Down Expand Up @@ -1134,6 +1134,7 @@ oled.batteryPercentage = function(percentage) {
var videoIntervalHandle = null;
var videoCallback = null;
var skipFrames = 0;
var fpsMultiplier = 0;
oled.video = function(videoPathFormat, frames, fps, callback) {
console.log("playing video, mode=", typeof frames);
if(oled.videoRunning) return callback && setTimeout(callback);
Expand All @@ -1153,7 +1154,7 @@ oled.video = function(videoPathFormat, frames, fps, callback) {
var indexString, paddingLength;
var frameComplete = true;
var frameLineFactor = (160 - 6) / frames;

fb.font(MENU_STATUS_FONT_SIZE, false, FONT_DEFAULT); fb.font(MENU_STATUS_FONT_SIZE, false, FONT_DEFAULT);
videoIntervalHandle = setInterval(function(){
if(!frameComplete) {
console.log("dropping frame #" + index);
Expand All @@ -1162,6 +1163,8 @@ oled.video = function(videoPathFormat, frames, fps, callback) {
frameComplete = false;
frameIndex += skipFrames;
skipFrames = 0;
if (fpsMultiplier > 0)
frameIndex += fpsMultiplier;
if(frameIndex > frames) oled.stopVideo();

if(frameArray) {
Expand All @@ -1182,6 +1185,16 @@ oled.video = function(videoPathFormat, frames, fps, callback) {
fb.line(3, 127 - 3, 159 - 3, 127 - 3, 2);
color("primary");
fb.line(3, 127 - 3, frameIndex * frameLineFactor, 127 - 3, 2);

var s = "x" + (fpsMultiplier + 1);
var textSize = fb.textSize(s);
var x = 160 - textSize.width - 4;
fb.color(0, 0, 0);
var y = 50;
fb.rect(x - 2, y - textSize.height, textSize.width + 4, textSize.height + 4, true);
color("primary");
fb.text(x, y, s);

fb.blit();
frameComplete = true;
}, 1000 / (fps||24));
Expand All @@ -1198,4 +1211,12 @@ oled.videoSkipFrames = function(frames) {
skipFrames = frames;
}
}
oled.increaseVideoSpeed = function () {
fpsMultiplier++;
if (fpsMultiplier > 15) fpsMultiplier = 15;
}
oled.decreaseVideoSpeed = function () {
fpsMultiplier--;
if (fpsMultiplier <=0) fpsMultiplier = 0;
}
module.exports = oled;
28 changes: 13 additions & 15 deletions intervalometer/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports.linear = function(xyPoints, xVal) {
}).sort(function(a, b) {
if(a.x < b.x) return -1;
if(a.x > b.x) return 1;
return 0;
return 0;
});

if(typeof p != 'object' || !p.length) return null;
Expand Down Expand Up @@ -46,8 +46,6 @@ exports.linear = function(xyPoints, xVal) {
if(res > limits.max) res = limits.max;
if(res < limits.min) res = limits.min;

console.log("Interpolated result:", res);

return res;
}

Expand Down Expand Up @@ -130,17 +128,17 @@ exports.catmullRomSpline = function(xyPoints, xVal) {
}).sort(function(a, b) {
if(a.x < b.x) return -1;
if(a.x > b.x) return 1;
return 0;
return 0;
});

if (!xyPoints || xyPoints.length == 0) {
return null;

} else if(xVal <= xyPoints[0].x) {
return xyPoints[0].y;
return xyPoints[0].y;

} else if(xVal >= xyPoints[xyPoints.length - 1].x) {
return xyPoints[xyPoints.length - 1].y;
return xyPoints[xyPoints.length - 1].y;

} else if(xyPoints.length == 1) {
return xyPoints[0].y;
Expand Down Expand Up @@ -218,12 +216,12 @@ exports.smooth = function(xyPoints, xVal) {
}
}
if(nextIndex == null) nextIndex = xyPoints.length - 1;

var tSpan = (xyPoints[nextIndex].x - xyPoints[lastIndex].x);
if(tSpan == 0) return xyPoints[lastIndex].y;
var t = (xVal - xyPoints[lastIndex].x) / tSpan;
var tS = smoothStep(t);

var lastSlope = pointSlope(lastIndex, xyPoints);
var nextSlope = pointSlope(nextIndex, xyPoints);

Expand All @@ -235,14 +233,14 @@ exports.smooth = function(xyPoints, xVal) {
if(Math.abs(nextVal - lastVal) > 0 && nextSlope > 0) d2 = (nextSlope * tSpan) / Math.abs(nextVal - lastVal);
var y1 = lastVal + (lastSlope * t*tSpan) / (1+d1*t);
var y2 = nextVal - (nextSlope * (1-t) * tSpan) / (1+d2*(1-t));

if(y1 > Math.max(lastVal, nextVal)) y1 = Math.max(lastVal, nextVal);
if(y2 > Math.max(lastVal, nextVal)) y2 = Math.max(lastVal, nextVal);
if(y1 < Math.min(lastVal, nextVal)) y1 = Math.min(lastVal, nextVal);
if(y2 < Math.min(lastVal, nextVal)) y2 = Math.min(lastVal, nextVal);

var y = (y1 * (1-tS)) + (y2 * tS);

return y;
}

Expand All @@ -257,17 +255,17 @@ exports.smoothStep = function(xyPoints, xVal) {
}
}
if(nextIndex == null) nextIndex = xyPoints.length - 1;

var tSpan = (xyPoints[nextIndex].x - xyPoints[lastIndex].x);
if(tSpan == 0) return xyPoints[lastIndex].y;
var t = (xVal - xyPoints[lastIndex].x) / tSpan;
var tS = smootherStep(t);

var lastVal = xyPoints[lastIndex].y;
var nextVal = xyPoints[nextIndex].y;

var y = (lastVal * (1-tS)) + (nextVal * tS);

return y;
}

10 changes: 9 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4694,7 +4694,15 @@ if (VIEW_HARDWARE) {

inputs.on('D', function(move) {
power.activity();
if(oled.videoRunning) return;
if(oled.videoRunning) {
if (move == "U") {
oled.increaseVideoSpeed();
}
if (move == "D") {
oled.decreaseVideoSpeed();
}
return;
}

blockGestureTimer();
if (blockInputs) return;
Expand Down

0 comments on commit 20c8a58

Please sign in to comment.