File size: 1,068 Bytes
a99b4ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cab8fdd
 
 
 
 
 
a99b4ac
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.copyFile(tmpFilePath, filePath)
        try {
          await fs.promises.unlink(tmpFilePath)
        } catch (err) {
          console.log('failed to cleanup (no big deal..)')
        }

        resolve(fileName)
      })
      .on('error', (err) => {
        reject(err)
      })
  })
}