mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
rename post-process
This commit is contained in:
parent
70778caba9
commit
6fcd98b070
@ -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
|
||||||
|
}
|
@ -3,12 +3,15 @@ import mimetypes from "mime-types"
|
|||||||
|
|
||||||
import processVideo from "./video"
|
import processVideo from "./video"
|
||||||
import processImage from "./image"
|
import processImage from "./image"
|
||||||
|
import processAudio from "./audio"
|
||||||
|
|
||||||
const fileTransformer = {
|
const fileTransformer = {
|
||||||
|
// video
|
||||||
"video/avi": processVideo,
|
"video/avi": processVideo,
|
||||||
"video/quicktime": processVideo,
|
"video/quicktime": processVideo,
|
||||||
"video/mp4": processVideo,
|
"video/mp4": processVideo,
|
||||||
"video/webm": processVideo,
|
"video/webm": processVideo,
|
||||||
|
//image
|
||||||
"image/jpeg": processImage,
|
"image/jpeg": processImage,
|
||||||
"image/png": processImage,
|
"image/png": processImage,
|
||||||
"image/gif": processImage,
|
"image/gif": processImage,
|
||||||
@ -16,6 +19,17 @@ const fileTransformer = {
|
|||||||
"image/tiff": processImage,
|
"image/tiff": processImage,
|
||||||
"image/webp": processImage,
|
"image/webp": processImage,
|
||||||
"image/jfif": 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) => {
|
export default async (file) => {
|
||||||
@ -30,7 +44,7 @@ export default async (file) => {
|
|||||||
const fileMimetype = mimetypes.lookup(file.filepath)
|
const fileMimetype = mimetypes.lookup(file.filepath)
|
||||||
|
|
||||||
if (typeof fileTransformer[fileMimetype] !== "function") {
|
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
|
return file
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user