diff --git a/downloader.mjs b/downloader.mjs index 122eba1..4c6d208 100644 --- a/downloader.mjs +++ b/downloader.mjs @@ -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++; diff --git a/index.mjs b/index.mjs index 3e0f97c..44a5c21 100644 --- a/index.mjs +++ b/index.mjs @@ -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'); diff --git a/video.mjs b/video.mjs index 7a0a49c..d6a1c3c 100644 --- a/video.mjs +++ b/video.mjs @@ -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) => {