cleaned old output on initialization

This commit is contained in:
Quentin Roussel
2024-08-18 18:57:21 +08:00
parent b189cd2351
commit 37073e11b2
3 changed files with 10 additions and 6 deletions

View File

@@ -50,16 +50,14 @@ function downloadImage(time_string, filepath) {
export async function initImages(count) {
let files = fs.readdirSync('images/raw');
for(let file of files) {
fs.unlinkSync(`images/raw/${file}`);
}
let downloaded = 0;
let i = 0;
while(downloaded < count) {
let time_string = getTimeString(i);
let filename = `images/raw/${time_string}.png`;
if (files.includes(`${time_string}.png`)) {
downloaded++;
i++;
continue;
}
try {
await downloadImage(time_string, filename);
downloaded++;

View File

@@ -1,7 +1,7 @@
import { initImages, updateImages } from './downloader.mjs';
import { createVideo } from './video.mjs';
const IMAGE_COUNT = 5;
const IMAGE_COUNT = 12;
initImages(IMAGE_COUNT).then(() => {
console.log('Downloaded initial images successfully');

View File

@@ -37,6 +37,12 @@ async function generateFinalImages() {
export async function createVideo() {
await generateFinalImages();
//remove video
try {
fs.unlinkSync('out/output.mp4');
} catch (error) {
console.log('No video to delete');
}
//run the command ffmpeg -framerate 5 -i %d.png -c:v libx264 -r 30 output.mp4
return new Promise((resolve, reject) => {
exec('ffmpeg -framerate 5 -i images/final/%d.png -c:v libx264 -r 30 out/output.mp4', (err, stdout, stderr) => {