rename post-process

This commit is contained in:
SrGooglo 2023-07-05 19:04:25 +00:00
parent 70778caba9
commit 6fcd98b070
4 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,30 @@
const ffmpeg = require("fluent-ffmpeg")
export default async (file) => {
// analize metadata
let metadata = await new Promise((resolve, reject) => {
ffmpeg.ffprobe(file.filepath, (err, data) => {
if (err) {
return reject(err)
}
resolve(data)
})
}).catch((err) => {
console.error(err)
return {}
})
if (metadata.format) {
metadata = metadata.format
}
file.metadata = {
duration: metadata.duration,
bitrate: metadata.bit_rate,
size: metadata.size,
}
return file
}

View File

@ -3,12 +3,15 @@ import mimetypes from "mime-types"
import processVideo from "./video"
import processImage from "./image"
import processAudio from "./audio"
const fileTransformer = {
// video
"video/avi": processVideo,
"video/quicktime": processVideo,
"video/mp4": processVideo,
"video/webm": processVideo,
//image
"image/jpeg": processImage,
"image/png": processImage,
"image/gif": processImage,
@ -16,6 +19,17 @@ const fileTransformer = {
"image/tiff": processImage,
"image/webp": processImage,
"image/jfif": processImage,
// audio
"audio/flac": processAudio,
"audio/x-flac": processAudio,
"audio/mp3": processAudio,
"audio/x-mp3": processAudio,
"audio/mpeg": processAudio,
"audio/x-mpeg": processAudio,
"audio/ogg": processAudio,
"audio/x-ogg": processAudio,
"audio/wav": processAudio,
"audio/x-wav": processAudio,
}
export default async (file) => {
@ -30,7 +44,7 @@ export default async (file) => {
const fileMimetype = mimetypes.lookup(file.filepath)
if (typeof fileTransformer[fileMimetype] !== "function") {
console.warn(`File (${file.filepath}) has mimetype ${fileMimetype} and will not be processed`)
console.debug(`File (${file.filepath}) has mimetype ${fileMimetype} and will not be processed`)
return file
}