Sfoglia il codice sorgente

handle ken-burns case with no zoom

master
Jonathan Cobb 3 anni fa
parent
commit
345ca10ceb
2 ha cambiato i file con 21 aggiunte e 6 eliminazioni
  1. +9
    -6
      src/main/java/jvc/operation/exec/KenBurnsExec.java
  2. +12
    -0
      src/test/resources/tests/test_ken_burns.jvc

+ 9
- 6
src/main/java/jvc/operation/exec/KenBurnsExec.java Vedi File

@@ -30,11 +30,13 @@ public class KenBurnsExec extends ExecBase<KenBurnsOperation> {
= "{{{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<KenBurnsOperation> {

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);


+ 12
- 0
src/test/resources/tests/test_ken_burns.jvc Vedi File

@@ -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)"
}]
}
]
}

Caricamento…
Annulla
Salva