This repository has been archived on 2021-09-20. You can view files and clone it, but cannot push or open issues or pull requests.
trol-bot-fork/shitpost.js
2021-09-03 02:04:05 +03:00

29 lines
No EOL
1,004 B
JavaScript

const { generateAudio } = require("./shitpost-audio.js");
const { generateFrames } = require("./shitpost-video.js");
const { spawn } = require("child_process");
const fs = require("fs");
async function generateVideo (sourceImg, duration)
{
let [framesPath, audioPath] = await Promise.all([
generateFrames(sourceImg, duration),
generateAudio(duration)
]);
const outputPath = `./temp/output_${Math.floor(Math.random() * 10000).toString().padStart(4, "0")}.mp4`;
const child = spawn(`ffmpeg -i ${audioPath} -r 20 -i ${framesPath}/%d.png -c:v libx264 -vf fps=20 -pix_fmt yuv420p ${outputPath}`, { shell: true })
child.on("exit", (code) => { finished = true; });
let finished = false;
while (!finished) await new Promise(resolve => setTimeout(resolve, 10));
// delete temp files
fs.promises.rm(framesPath, { recursive: true });
fs.promises.rm(audioPath);
fs.promises.rm(sourceImg);
return outputPath;
}
module.exports = { generateVideo };