Skip to content

Commit

Permalink
remove unnecesary mode and make sure tmp file is deleted on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
juandjara committed May 12, 2020
1 parent a60f208 commit c8a6a71
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions api/converter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const fs = require('fs')
const del = require('del')
const axios = require('axios')
const tempy = require('tempy')
const ffmpeg = require('fluent-ffmpeg')
Expand Down Expand Up @@ -30,9 +29,15 @@ async function processVideo (job, done) {
}
}

function ffmpegCommand (path, job, done) {
function ffmpegCommand (tempPath, job, done) {
let duration = 0
const command = ffmpeg(path)

async function deleteTempFile () {
await fs.promises.unlink(tempPath)
job.log(`[converter.js] Deleted temporary file in ${tempPath}`)
}

const command = ffmpeg(tempPath)
.videoCodec('libvpx')
.audioCodec('libvorbis')
.format('webm')
Expand Down Expand Up @@ -60,6 +65,7 @@ function ffmpegCommand (path, job, done) {
if (!isActive) {
job.log(`[converter.js] Detected inactive job #${job.id}. Stopping ffmpeg process.`)
command.kill()
await deleteTempFile()
return
}

Expand All @@ -69,9 +75,8 @@ function ffmpegCommand (path, job, done) {
job.progress(percent)
})
.on('end', async () => {
const deleted = await del([path], { force: true })
await deleteTempFile()
job.progress(100)
job.log(`[converter.js] Deleted temporary file in ${deleted}`)
done(null, getVideoName(job))
})
.saveToFile(getVideoName(job))
Expand Down

0 comments on commit c8a6a71

Please sign in to comment.