mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
44 lines
1.2 KiB
JavaScript
Executable File
44 lines
1.2 KiB
JavaScript
Executable File
import videoTranscode from "@services/videoTranscode"
|
|
|
|
/**
|
|
* Processes a video file based on the specified options.
|
|
*
|
|
* @async
|
|
* @param {Object} file - The video file to process.
|
|
* @param {Object} [options={}] - The options object to use for processing.
|
|
* @param {string} [options.videoCodec="libx264"] - The video codec to use.
|
|
* @param {string} [options.format="mp4"] - The format to use.
|
|
* @param {number} [options.audioBitrate=128] - The audio bitrate to use.
|
|
* @param {number} [options.videoBitrate=2024] - The video bitrate to use.
|
|
* @throws {Error} Throws an error if file parameter is not provided.
|
|
* @return {Object} The processed video file object.
|
|
*/
|
|
async function processVideo(file, options = {}) {
|
|
if (!file) {
|
|
throw new Error("file is required")
|
|
}
|
|
|
|
// TODO: Get values from db
|
|
const {
|
|
videoCodec = "libx264",
|
|
format = "mp4",
|
|
audioBitrate = 128,
|
|
videoBitrate = 3000,
|
|
} = options
|
|
|
|
const result = await videoTranscode(file.filepath, {
|
|
videoCodec,
|
|
format,
|
|
audioBitrate,
|
|
videoBitrate: [videoBitrate, true],
|
|
extraOptions: ["-threads 2"],
|
|
})
|
|
|
|
file.filepath = result.filepath
|
|
file.filename = result.filename
|
|
|
|
return file
|
|
}
|
|
|
|
export default processVideo
|