media-server / src /enhanceVideo.mts
jbilcke-hf's picture
jbilcke-hf HF staff
read for batch 3
a99b4ac
raw
history blame
911 Bytes
import path from 'node:path'
import fs from 'node:fs'
import tmpDir from 'temp-dir'
import ffmpeg from 'fluent-ffmpeg'
export const enhanceVideo = async (fileName: string): Promise<string> => {
return new Promise((resolve,reject) => {
const tmpFileName = `enhanced_${fileName}.mp4`
const filePath = path.join(tmpDir, fileName)
const tmpFilePath = path.join(tmpDir, tmpFileName)
ffmpeg(filePath)
// the basic interpolation create weird fade effects
// .videoFilters('minterpolate=fps=12:mi_mode=mci:mc_mode=aobmc:me_mode=bidir:vsbmc=1')
// we should already be upscaled at this point
// .size('1024x576')
.videoFilters('noise=c0s=10:c0f=t+u')
.save(tmpFilePath)
.on('end', async () => {
await fs.promises.rename(tmpFilePath, filePath)
resolve(fileName)
})
.on('error', (err) => {
reject(err)
})
})
}