From 7353159382d5f85f0b50388f06669eda8c029bf8 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 14 Oct 2020 11:17:39 +0200 Subject: [PATCH] add dummy transition --- README.md | 2 +- examples/audio-transition.json5 | 6 +++++- index.js | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b6e2a03..5ff448e 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ Edit specs are JavaScript / JSON objects describing the whole edit operation wit ### Transition types -`transition.name` can be any of [gl-transitions](https://gl-transitions.com/gallery), or any of the following: `directional-left`, `directional-right`, `directional-up`, `directional-down` and `random`. +`transition.name` can be any of [gl-transitions](https://gl-transitions.com/gallery), or any of the following: `directional-left`, `directional-right`, `directional-up`, `directional-down`, `random` or `dummy`. ### Layer types diff --git a/examples/audio-transition.json5 b/examples/audio-transition.json5 index f465a0d..01fd8f9 100644 --- a/examples/audio-transition.json5 +++ b/examples/audio-transition.json5 @@ -23,9 +23,13 @@ { type: 'title-background', text: 'Clip 4' }, { type: 'audio', path: './assets/sample2.m4a' } ] }, - { layers: [ + { transition: { name: 'dummy' }, layers: [ { type: 'title-background', text: 'Clip 5' }, { type: 'audio', path: './assets/sample1.m4a' } ] }, + { layers: [ + { type: 'title-background', text: 'Clip 6' }, + { type: 'audio', path: './assets/sample2.m4a' } + ] }, ], } diff --git a/index.js b/index.js index 9d61511..88b2a08 100644 --- a/index.js +++ b/index.js @@ -152,7 +152,14 @@ const Editly = async (config = {}) => { return newAcc; }, 0); - const { runTransitionOnFrame } = GlTransitions({ width, height, channels }); + const { runTransitionOnFrame: runGlTransitionOnFrame } = GlTransitions({ width, height, channels }); + + function runTransitionOnFrame({ fromFrame, toFrame, progress, transitionName, transitionParams }) { + // A dummy transition can be used to have an audio transition without a video transition + // (Note: You will lose a portion from both clips due to overlap) + if (transitionName === 'dummy') return progress > 0.5 ? toFrame : fromFrame; + return runGlTransitionOnFrame({ fromFrame, toFrame, progress, transitionName, transitionParams }); + } function startFfmpegWriterProcess() { // https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality