@@ -3,12 +3,12 @@ import { registerFont } from "canvas";
3
3
import flatMap from "lodash-es/flatMap.js" ;
4
4
import pMap from "p-map" ;
5
5
import { basename } from "path" ;
6
+ import { Configuration } from "./configuration.js" ;
6
7
import { readDuration , readVideoFileInfo } from "./ffmpeg.js" ;
7
8
import { Transition } from "./transition.js" ;
8
9
import type {
9
10
AudioTrack ,
10
11
CanvasLayer ,
11
- Clip ,
12
12
FabricLayer ,
13
13
ImageLayer ,
14
14
ImageOverlayLayer ,
@@ -49,13 +49,12 @@ async function validateArbitraryAudio(
49
49
}
50
50
51
51
type ParseConfigOptions = {
52
- clips : Clip [ ] ;
53
- backgroundAudioVolume ?: string | number ;
54
52
backgroundAudioPath ?: string ;
55
- loopAudio ?: boolean ;
56
- allowRemoteRequests ?: boolean ;
57
53
arbitraryAudio : AudioTrack [ ] ;
58
- } ;
54
+ } & Pick <
55
+ Configuration ,
56
+ "clips" | "backgroundAudioVolume" | "loopAudio" | "allowRemoteRequests" | "defaults"
57
+ > ;
59
58
60
59
export default async function parseConfig ( {
61
60
clips,
@@ -64,6 +63,7 @@ export default async function parseConfig({
64
63
backgroundAudioVolume,
65
64
loopAudio,
66
65
allowRemoteRequests,
66
+ defaults,
67
67
} : ParseConfigOptions ) {
68
68
async function handleLayer ( layer : Layer ) : Promise < Layer | Layer [ ] > {
69
69
// https://github.com/mifi/editly/issues/39
@@ -122,14 +122,8 @@ export default async function parseConfig({
122
122
let clipsOut : ProcessedClip [ ] = await pMap (
123
123
clips ,
124
124
async ( clip , clipIndex ) => {
125
- const { transition : userTransition , duration, layers } = clip ;
126
-
127
- const videoLayers = layers . filter ( ( layer ) => layer . type === "video" ) ;
128
-
129
- if ( videoLayers . length === 0 )
130
- assert ( duration , `Duration parameter is required for videoless clip ${ clipIndex } ` ) ;
131
-
132
- const transition = new Transition ( userTransition , clipIndex === clips . length - 1 ) ;
125
+ const { layers } = clip ;
126
+ const transition = new Transition ( clip . transition , clipIndex === clips . length - 1 ) ;
133
127
134
128
let layersOut = flatMap (
135
129
await pMap (
@@ -179,13 +173,14 @@ export default async function parseConfig({
179
173
) ,
180
174
) ;
181
175
182
- let clipDuration = duration ;
176
+ let clipDuration = clip . duration ;
183
177
184
- const firstVideoLayer = layersOut . find (
185
- ( layer ) : layer is VideoLayer => layer . type === "video" ,
186
- ) ;
187
- if ( firstVideoLayer && ! duration ) clipDuration = firstVideoLayer . layerDuration ! ;
188
- assert ( clipDuration ) ;
178
+ if ( ! clipDuration ) {
179
+ const video = layersOut . find ( ( layer ) : layer is VideoLayer => layer . type === "video" ) ;
180
+ clipDuration = video ?. layerDuration ?? defaults . duration ;
181
+ }
182
+
183
+ assert ( clipDuration , `Duration parameter is required for videoless clip ${ clipIndex } ` ) ;
189
184
190
185
// We need to map again, because for audio, we need to know the correct clipDuration
191
186
layersOut = (
@@ -229,9 +224,9 @@ export default async function parseConfig({
229
224
let speedFactor ;
230
225
231
226
// If user explicitly specified duration for clip, it means that should be the output duration of the video
232
- if ( duration ) {
227
+ if ( clipDuration ) {
233
228
// Later we will speed up or slow down video using this factor
234
- speedFactor = duration / layerDuration ;
229
+ speedFactor = clipDuration / layerDuration ;
235
230
} else {
236
231
speedFactor = 1 ;
237
232
}
0 commit comments