From 0cc022d6cdb98eac9b44bd182e93f6560482394c Mon Sep 17 00:00:00 2001 From: MiguVT Date: Mon, 2 Dec 2024 19:26:44 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20extension=20bug=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/mediaProcessor.js | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index e983886..3ae5667 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "tailwindcss": "^3.4.15" }, "name": "media-processor-pro", - "version": "1.0.1", + "version": "1.0.1a", "description": "Media Processor Pro - Generador de variaciones de videos e imágenes", "author": "MiguVT", "main": "main.js", diff --git a/src/mediaProcessor.js b/src/mediaProcessor.js index e4a0f2d..e14a2c7 100644 --- a/src/mediaProcessor.js +++ b/src/mediaProcessor.js @@ -2,23 +2,14 @@ const ffmpeg = require('fluent-ffmpeg'); const sharp = require('sharp'); const path = require('path'); const { EventEmitter } = require('events'); -const { app } = require('electron'); -const { getFfmpegPaths } = require('./validators') +const { isImage } = require('./validators'); class MediaProcessor extends EventEmitter { constructor(inputPath) { super(); this.inputPath = inputPath; this.outputDir = path.dirname(inputPath); - - // Configurar FFmpeg - const { ffmpeg: ffmpegbin, ffprobe: ffprobebin } = getFfmpegPaths(); - - console.log('FFmpeg Path:', ffmpegbin); - console.log('FFprobe Path:', ffprobebin); - - ffmpeg.setFfmpegPath(ffmpegbin); - ffmpeg.setFfprobePath(ffprobebin); + this.isImageFile = isImage(inputPath); } async generateVariants(count) { @@ -42,15 +33,21 @@ class MediaProcessor extends EventEmitter { return results; } + getOutputPath(index) { + const extension = path.extname(this.inputPath); + const prefix = this.isImageFile ? 'output_image' : 'output_video'; + return path.join(this.outputDir, `${prefix}_${index}${extension}`); + } + async processMedia(index) { - if (this.isImage) { + if (this.isImageFile) { return this.processImage(index); } return this.processVideo(index); } async processImage(index) { - const outputPath = path.join(this.outputDir, `output_image_${index}${path.extname(this.inputPath)}`); + const outputPath = this.getOutputPath(index); try { const image = sharp(this.inputPath); @@ -81,7 +78,7 @@ class MediaProcessor extends EventEmitter { } async processVideo(index) { - const outputPath = path.join(this.outputDir, `output_video_${index}.mp4`); + const outputPath = this.getOutputPath(index); return new Promise((resolve, reject) => { const command = ffmpeg(this.inputPath);