From 20c8a58181bd3d6b61532b8c0372f4d0e1d7a2ba Mon Sep 17 00:00:00 2001 From: naixx Date: Tue, 11 Jun 2024 23:28:36 +0300 Subject: [PATCH] Add an option to speed up timelapse clips in video preview mode. Just turn dial up or down --- hardware/oled.js | 25 +++++++++++++++++++++++-- intervalometer/interpolate.js | 28 +++++++++++++--------------- main.js | 10 +++++++++- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/hardware/oled.js b/hardware/oled.js index 1de95869..65d27f2a 100644 --- a/hardware/oled.js +++ b/hardware/oled.js @@ -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++) { @@ -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); @@ -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); @@ -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) { @@ -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)); @@ -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; diff --git a/intervalometer/interpolate.js b/intervalometer/interpolate.js index fa19a701..23836632 100644 --- a/intervalometer/interpolate.js +++ b/intervalometer/interpolate.js @@ -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; @@ -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; } @@ -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; @@ -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); @@ -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; } @@ -257,7 +255,7 @@ 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; @@ -265,9 +263,9 @@ exports.smoothStep = function(xyPoints, xVal) { var lastVal = xyPoints[lastIndex].y; var nextVal = xyPoints[nextIndex].y; - + var y = (lastVal * (1-tS)) + (nextVal * tS); - + return y; } diff --git a/main.js b/main.js index d28a3a48..ff0ae43e 100644 --- a/main.js +++ b/main.js @@ -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;