hazycora
4fbe774841
It wont wrap long linesnode .! ughhnode .node . i dont know how to fix this otherwise ihml
30 lines
888 B
JavaScript
30 lines
888 B
JavaScript
import { spawn } from 'child_process'
|
|
import { getTextFilter } from './utils.js'
|
|
|
|
export async function addTextOverlay(file, text) {
|
|
const textFilter = await getTextFilter(text, file)
|
|
let ffmpegProc = spawn('ffmpeg', [
|
|
'-y',
|
|
'-i', file.path,
|
|
'-movflags', 'frag_keyframe+empty_moov+faststart',
|
|
'-b:v', `${Math.min(64000 / file.duration - 20, file.bitrateKb)}k`,
|
|
'-b:a', '20k',
|
|
'-c:v', 'libx264',
|
|
'-ac', '1',
|
|
'-filter:v', `fps=fps=15,scale=${Math.min(file.width, 640)}:-2,${textFilter}`,
|
|
'-preset', 'ultrafast',
|
|
'-f', 'mp4',
|
|
'-'
|
|
])
|
|
let errDat = []
|
|
ffmpegProc.stderr.on('data', dat => errDat.push(dat))
|
|
ffmpegProc.on('close', code => {
|
|
if (!code || code == 0) return
|
|
console.log(Buffer.concat(errDat).toString())
|
|
console.log(`ffmpeg exited with error ^, code ${code}`)
|
|
})
|
|
return {
|
|
stream: ffmpegProc.stdout,
|
|
kill: () => ffmpegProc.kill('SIGKILL')
|
|
}
|
|
} |