diff --git a/src/main/java/jvc/operation/exec/KenBurnsExec.java b/src/main/java/jvc/operation/exec/KenBurnsExec.java index b421aa0..922d89b 100644 --- a/src/main/java/jvc/operation/exec/KenBurnsExec.java +++ b/src/main/java/jvc/operation/exec/KenBurnsExec.java @@ -30,11 +30,13 @@ public class KenBurnsExec extends ExecBase { = "{{{ffmpeg}}} -i {{{source.path}}} -filter_complex \"" + "scale={{expr width '*' upscale}}x{{expr height '*' upscale}}, " + "zoompan=" - + "z='{{#exists startFrame}}" - + "if(between(in,{{startFrame}},{{endFrame}}),min(zoom+{{zoomIncrementFactor}},{{zoom}}),{{zoom}})" - + "{{else}}" - + "z='min(zoom+{{zoomIncrementFactor}},{{zoom}})':" - + "{{/exists}}':" + + "{{#if hasZoom}}" + + "z='{{#exists startFrame}}" + + "if(between(in,{{startFrame}},{{endFrame}}),min(zoom+{{zoomIncrementFactor}},{{zoom}}),{{zoom}})" + + "{{else}}" + + "z='min(zoom+{{zoomIncrementFactor}},{{zoom}})':" + + "{{/exists}}':" + + "{{/if}}" + "d={{totalFrames}}:" + "fps={{fps}}:" + "x='if(gte(zoom,{{zoom}}),x,x{{deltaXSign}}{{deltaX}}/a)':" @@ -75,12 +77,13 @@ public class KenBurnsExec extends ExecBase { final BigDecimal zoom = op.getZoom(ctx, js); final BigDecimal totalFrames = duration.multiply(fps); - final BigDecimal zoomIncrementFactor = divideBig(zoom.subtract(ONE), totalFrames); + final BigDecimal zoomIncrementFactor = zoom.equals(ONE) ? ZERO : divideBig(zoom.subtract(ONE), totalFrames); ctx.put("zoom", zoom); ctx.put("fps", fps.intValue()); ctx.put("totalFrames", totalFrames.intValue()); ctx.put("zoomIncrementFactor", zoomIncrementFactor); + ctx.put("hasZoom", !zoomIncrementFactor.equals(ZERO)); final BigDecimal midX = divideBig(source.getWidth(), TWO); final BigDecimal midY = divideBig(source.getHeight(), TWO); diff --git a/src/test/resources/tests/test_ken_burns.jvc b/src/test/resources/tests/test_ken_burns.jvc index d38829c..85b54a2 100644 --- a/src/test/resources/tests/test_ken_burns.jvc +++ b/src/test/resources/tests/test_ken_burns.jvc @@ -9,6 +9,7 @@ ], "operations": [ { + "comment": "full example - all operation params are specified", "operation": "ken-burns", // name of the operation "creates": "ken1", // asset it creates "source": "javelin.jpg", // source image @@ -27,6 +28,17 @@ "comment": "expect output resolution of 1024x768", "test": "output.width === 1024 && output.height === 768" }] + }, + { + "comment": "minimal example - only duration is specified", + "operation": "ken-burns", + "creates": "ken2", + "source": "javelin.jpg", + "duration": "5", + "validate": [{ + "comment": "expect output to be about 5 seconds long, give or take 0.1 seconds", + "test": "is_within(output.duration, 5, 0.1)" + }] } ] }