@yaron24/ffmpeg-concat
Version:
Concats a list of videos together using ffmpeg with sexy OpenGL transitions.
82 lines (63 loc) • 1.51 kB
JavaScript
const GL = require('gl')
const createFrameWriter = require('./frame-writer')
const createTransition = require('./transition')
module.exports = async (opts) => {
const {
frameFormat,
theme
} = opts
const {
width,
height
} = theme
const gl = GL(width, height)
if (!gl) {
console.error('Failed to create OpenGL context. Please see https://github.com/stackgl/headless-gl#supported-platforms-and-nodejs-versions for compatibility.')
throw new Error('failed to create OpenGL context')
}
const frameWriter = await createFrameWriter({
gl,
width,
height,
frameFormat
})
const ctx = {
gl,
width,
height,
frameWriter,
transition: null
}
ctx.setTransition = ({ name, resizeMode }) => {
if (ctx.transition) {
if (ctx.transition.name === name) {
return
}
ctx.transition.dispose()
ctx.transition = null
}
ctx.transition = createTransition({
gl,
name,
resizeMode
})
}
ctx.capture = ctx.frameWriter.write.bind(ctx.frameWriter)
ctx.render = async (...args) => {
if (ctx.transition) {
return ctx.transition.draw(...args)
}
}
ctx.flush = async () => {
return ctx.frameWriter.flush()
}
ctx.dispose = async () => {
if (ctx.transition) {
ctx.transition.dispose()
ctx.transition = null
}
gl.destroy()
}
return ctx
}