"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateThumbnailFromVideo = exports.processGIF = exports.convertWebPToJPG = void 0;
const tslib_1 = require("tslib");
const fluent_ffmpeg_1 = tslib_1.__importDefault(require("fluent-ffmpeg"));
const constants_1 = require("../../initializers/constants");
const ffmpeg_commons_1 = require("./ffmpeg-commons");
function convertWebPToJPG(path, destination) {
    const command = (0, fluent_ffmpeg_1.default)(path, { niceness: constants_1.FFMPEG_NICE.THUMBNAIL })
        .output(destination);
    return (0, ffmpeg_commons_1.runCommand)({ command, silent: true });
}
exports.convertWebPToJPG = convertWebPToJPG;
function processGIF(path, destination, newSize) {
    const command = (0, fluent_ffmpeg_1.default)(path, { niceness: constants_1.FFMPEG_NICE.THUMBNAIL })
        .fps(20)
        .size(`${newSize.width}x${newSize.height}`)
        .output(destination);
    return (0, ffmpeg_commons_1.runCommand)({ command });
}
exports.processGIF = processGIF;
function generateThumbnailFromVideo(fromPath, folder, imageName) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const pendingImageName = 'pending-' + imageName;
        const options = {
            filename: pendingImageName,
            count: 1,
            folder
        };
        return new Promise((res, rej) => {
            (0, fluent_ffmpeg_1.default)(fromPath, { niceness: constants_1.FFMPEG_NICE.THUMBNAIL })
                .on('error', rej)
                .on('end', () => res(imageName))
                .thumbnail(options);
        });
    });
}
exports.generateThumbnailFromVideo = generateThumbnailFromVideo;
//# sourceMappingURL=ffmpeg-images.js.map