Skip to content

Commit

Permalink
🐛 extension bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguVT committed Dec 2, 2024
1 parent f0b0335 commit 0cc022d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 11 additions & 14 deletions src/mediaProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0cc022d

Please sign in to comment.