File size: 795 Bytes
ccd48b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import path from "node:path"

import { v4 as uuidv4 } from "uuid"
import tmpDir from "temp-dir"
import ffmpeg from "fluent-ffmpeg"

import { pendingFilesDirFilePath } from "../config.mts"

export const normalizePendingVideoToTmpFilePath = async (fileName: string): Promise<string> => {
  return new Promise((resolve,reject) => {

    const tmpFileName = `${uuidv4()}.mp4`

    const filePath = path.join(pendingFilesDirFilePath, fileName)
    const tmpFilePath = path.join(tmpDir, tmpFileName)

    ffmpeg.ffprobe(filePath, function(err,) {
      if (err) { reject(err); return; }

    ffmpeg(filePath)

      .size("1280x720")

      .save(tmpFilePath)
      .on("end", async () => {
        resolve(tmpFilePath)
      })
      .on("error", (err) => {
        reject(err)
      })
    })
  })
}