56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
const ffmpeg = require("fluent-ffmpeg");
|
|
|
|
module.exports = {
|
|
/**
|
|
* reads information from a video
|
|
* @param {*} inputPath path to video file
|
|
* @returns promise <video size, videoduration>
|
|
*/
|
|
'getVideoInfo': (inputPath) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (typeof(inputPath) != "string") {
|
|
return reject("path must be of type string");
|
|
}
|
|
|
|
return ffmpeg.ffprobe(inputPath, (error, videoInfo) => {
|
|
|
|
if (error) {
|
|
return reject(error);
|
|
}
|
|
|
|
const { duration, size } = videoInfo.format;
|
|
|
|
return resolve({
|
|
size,
|
|
durationInSeconds: Math.floor(duration),
|
|
});
|
|
});
|
|
});
|
|
},
|
|
'scaleVideo': (options) => {
|
|
ffmpeg(options.inputPath)
|
|
.size(`${options.width}x${options.height}`)
|
|
.videoBitrate(options.bitrate)
|
|
.save(options.outputPath)
|
|
.on('end', () => {
|
|
console.log('Video resolution and file size have been changed successfully!');
|
|
})
|
|
.on('error', (err) => {
|
|
console.log('Error: ' + err.message);
|
|
});
|
|
},
|
|
/**
|
|
* encodes video with given parameters
|
|
* @param {object} options JSON Object passed as settings
|
|
* @returns promise
|
|
*/
|
|
'encodeVideo': (options) => {
|
|
// TODO: figure my shit out
|
|
// Literally dont fucking know how to do this -.-
|
|
// Future me be smarter best of luck.. past me.
|
|
},
|
|
'generateThumbnail': () => {
|
|
|
|
}
|
|
} |