|
|
@ -70,14 +70,14 @@ const Editly = async (config = {}) => { |
|
|
if (verbose) console.log(JSON5.stringify(clips, null, 2)); |
|
|
if (verbose) console.log(JSON5.stringify(clips, null, 2)); |
|
|
|
|
|
|
|
|
// Try to detect parameters from first video
|
|
|
// Try to detect parameters from first video
|
|
|
let detectedWidth; |
|
|
|
|
|
let detectedHeight; |
|
|
|
|
|
|
|
|
let firstVideoWidth; |
|
|
|
|
|
let firstVideoHeight; |
|
|
let firstVideoFramerateStr; |
|
|
let firstVideoFramerateStr; |
|
|
|
|
|
|
|
|
clips.find((clip) => clip && clip.layers.find((layer) => { |
|
|
clips.find((clip) => clip && clip.layers.find((layer) => { |
|
|
if (layer.type === 'video') { |
|
|
if (layer.type === 'video') { |
|
|
detectedWidth = layer.inputWidth; |
|
|
|
|
|
detectedHeight = layer.inputHeight; |
|
|
|
|
|
|
|
|
firstVideoWidth = layer.inputWidth; |
|
|
|
|
|
firstVideoHeight = layer.inputHeight; |
|
|
firstVideoFramerateStr = layer.framerateStr; |
|
|
firstVideoFramerateStr = layer.framerateStr; |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
@ -90,18 +90,19 @@ const Editly = async (config = {}) => { |
|
|
|
|
|
|
|
|
let desiredWidth; |
|
|
let desiredWidth; |
|
|
|
|
|
|
|
|
if (fast) desiredWidth = 320; |
|
|
|
|
|
else if (requestedWidth) desiredWidth = requestedWidth; |
|
|
|
|
|
|
|
|
if (requestedWidth) desiredWidth = requestedWidth; |
|
|
else if (isGif) desiredWidth = 320; |
|
|
else if (isGif) desiredWidth = 320; |
|
|
|
|
|
|
|
|
if (detectedWidth && detectedHeight) { |
|
|
|
|
|
|
|
|
const roundDimension = (val) => (isGif ? Math.round(val) : multipleOf2(val)); |
|
|
|
|
|
|
|
|
|
|
|
if (firstVideoWidth && firstVideoHeight) { |
|
|
if (desiredWidth) { |
|
|
if (desiredWidth) { |
|
|
const calculatedHeight = Math.round((detectedHeight / detectedWidth) * desiredWidth); |
|
|
|
|
|
height = isGif ? calculatedHeight : multipleOf2(calculatedHeight); // x264 requires multiple of 2
|
|
|
|
|
|
|
|
|
const calculatedHeight = (firstVideoHeight / firstVideoWidth) * desiredWidth; |
|
|
|
|
|
height = roundDimension(calculatedHeight); |
|
|
width = desiredWidth; |
|
|
width = desiredWidth; |
|
|
} else { |
|
|
} else { |
|
|
width = detectedWidth; |
|
|
|
|
|
height = detectedHeight; |
|
|
|
|
|
|
|
|
width = firstVideoWidth; |
|
|
|
|
|
height = firstVideoHeight; |
|
|
} |
|
|
} |
|
|
} else if (desiredWidth) { |
|
|
} else if (desiredWidth) { |
|
|
width = desiredWidth; |
|
|
width = desiredWidth; |
|
|
@ -114,14 +115,27 @@ const Editly = async (config = {}) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// User override?
|
|
|
// User override?
|
|
|
if (!fast && requestedWidth && requestedHeight) { |
|
|
|
|
|
|
|
|
if (requestedWidth && requestedHeight) { |
|
|
width = requestedWidth; |
|
|
width = requestedWidth; |
|
|
height = requestedHeight; |
|
|
height = requestedHeight; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fast) { |
|
|
|
|
|
const numPixelsEachDirection = 250; |
|
|
|
|
|
const aspectRatio = width / height; |
|
|
|
|
|
width = roundDimension(numPixelsEachDirection * Math.sqrt(aspectRatio)); |
|
|
|
|
|
height = roundDimension(numPixelsEachDirection * Math.sqrt(1 / aspectRatio)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
assert(width, 'Width not specified or detected'); |
|
|
assert(width, 'Width not specified or detected'); |
|
|
assert(height, 'Height not specified or detected'); |
|
|
assert(height, 'Height not specified or detected'); |
|
|
|
|
|
|
|
|
|
|
|
if (!isGif) { |
|
|
|
|
|
// x264 requires multiple of 2, eg minimum 2
|
|
|
|
|
|
width = Math.max(2, width); |
|
|
|
|
|
height = Math.max(2, height); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let fps; |
|
|
let fps; |
|
|
let framerateStr; |
|
|
let framerateStr; |
|
|
|
|
|
|
|
|
|