Skip to content

Commit

Permalink
feat: Modify the usage from ffmpeg-probe
Browse files Browse the repository at this point in the history
* Modify the usage from ffmpeg-probe to ffmpeg.ffprobe approach.
* Add a setFFPath method to set the path to ffmpeg on your machine.
* Increase the number of catch logs for better error handling and debugging.
  • Loading branch information
drawcall committed Jul 24, 2024
1 parent 65dc4fd commit f6f2bba
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v7.5.1
* Modify the usage from ffmpeg-probe to ffmpeg.ffprobe approach.
* Add a setFFPath method to set the path to ffmpeg on your machine.
* Increase the number of catch logs for better error handling and debugging.

## v7.3.5
* Add FFmpegUtil captureVideoFrame function.
* Add FFmpegUtil convertVideoToGif function.
Expand Down
2 changes: 2 additions & 0 deletions examples/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const colors = require('colors');
const startAndListen = require('./listen');
const { FFCreatorCenter, FFAudio, FFScene, FFImage, FFGifImage, FFCreator } = require('../');

FFCreator.setFFPath();

const createFFTask = () => {
const bg1 = path.join(__dirname, './assets/imgs/bg/06.jpg');
const bg2 = path.join(__dirname, './assets/imgs/bg/01.jpeg');
Expand Down
4 changes: 4 additions & 0 deletions lib/center/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ const FFCreatorCenter = {
setFFprobePath(path) {
FFmpegUtil.setFFprobePath(path);
},

setFFPath() {
FFmpegUtil.setFFPath();
}
};

module.exports = FFCreatorCenter;
4 changes: 4 additions & 0 deletions lib/creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ class FFCreator extends FFCon {
static setFFprobePath(path) {
FFmpegUtil.setFFprobePath(path);
}

static setFFPath() {
FFmpegUtil.setFFPath();
}
}

module.exports = FFCreator;
7 changes: 4 additions & 3 deletions lib/node/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
const path = require('path');
const FS = require('../utils/fs');
const FFImage = require('./image');
const probe = require('ffmpeg-probe');
const { Sprite, Texture } = require('inkpaint');
const FFLogger = require('../utils/logger');
const FFmpegUtil = require('../utils/ffmpeg');
const ffprobe = require('../utils/ffprobe');
const Materials = require('../utils/materials');
const TimelineUpdate = require('../timeline/update');

Expand Down Expand Up @@ -68,7 +68,8 @@ class FFGifImage extends FFImage {
const info = await this.geGifInfo();
fps = Number(info.fps);
} catch (e) {
console.log(this.getPath(), e);
console.log(this.getPath());
console.log(e);
}
return await this.extractGif(fps);
}
Expand Down Expand Up @@ -139,7 +140,7 @@ class FFGifImage extends FFImage {
* @private
*/
async geGifInfo() {
return await probe(this.getPath());
return await ffprobe(this.getPath());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/node/subtitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* @class
*/
const FFNode = require('./node');
const probe = require('ffmpeg-probe');
const forEach = require('lodash/forEach');
const FFTween = require('../animate/tween');
const DateUtil = require('../utils/date');
const ffprobe = require('../utils/ffprobe');
const CanvasUtil = require('../utils/canvas');
const Materials = require('../utils/materials');
const TimelineUpdate = require('../timeline/update');
Expand Down Expand Up @@ -208,7 +208,7 @@ class FFSubtitle extends FFNode {

async preProcessing() {
if (this.conf.speech) {
this.materials.info = await probe(this.conf.speech);
this.materials.info = await ffprobe(this.conf.speech);
const duration = this.materials.getDuration();
this.setDuration(duration);
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/node/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const path = require('path');
const min = require('lodash/min');
const FS = require('../utils/fs');
const FFImage = require('./image');
const probe = require('ffmpeg-probe');
const FFAudio = require('../audio/audio');
const DateUtil = require('../utils/date');
const FFLogger = require('../utils/logger');
const ffprobe = require('../utils/ffprobe');
const FFmpegUtil = require('../utils/ffmpeg');
const Materials = require('../utils/materials');
const TimelineUpdate = require('../timeline/update');
Expand Down Expand Up @@ -350,7 +350,7 @@ class FFVideo extends FFImage {
}

async getVideoInfo() {
return await probe(this.getPath());
return await ffprobe(this.getPath());
}

getVOutput() {
Expand Down
15 changes: 11 additions & 4 deletions lib/utils/ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
*
* @object
*/
const path = require('path');
const siz = require('siz');
const Utils = require('./utils');
const path = require('path');
const ffmpeg = require('fluent-ffmpeg');
const isArray = require('lodash/isArray');
const forEach = require('lodash/forEach');
const ffmpeg = require('fluent-ffmpeg');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffprobeInstaller = require('@ffprobe-installer/ffprobe');
const Utils = require('./utils');

const FFmpegUtil = {
/**
Expand Down Expand Up @@ -51,6 +53,11 @@ const FFmpegUtil = {
ffmpeg.setFfprobePath(path);
},

setFFPath() {
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
ffmpeg.setFfprobePath(ffprobeInstaller.path);
},

/**
* Set a water mark for swpan stdin
*
Expand Down Expand Up @@ -148,7 +155,7 @@ const FFmpegUtil = {
ffmpeg(input)
.output(output)
.videoFilters([`fps=${fps}`, `scale=${width}:-1`])
.outputOptions('-loop 0')
.outputOptions('-loop 0')
.on('end', () => {
resolve(output);
})
Expand Down
33 changes: 33 additions & 0 deletions lib/utils/ffprobe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

/**
* ffprobe - a Compatible FFmpeg Probe Method
*
* ####Example:
*
*
*
* @object
*/
const probe = require('ffmpeg-probe');
const ffmpeg = require('fluent-ffmpeg');

const useFluent = true;
const ffprobe = filePath => {
if (useFluent) {
return new Promise((resolve, reject) => {
ffmpeg.ffprobe(filePath, (err, metadata) => {
if (err) {
reject(err);
} else {
// console.log(metadata);
resolve(metadata);
}
});
});
} else {
return probe(filePath);
}
};

module.exports = ffprobe;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffcreator",
"version": "7.3.6",
"version": "7.5.1",
"description": "FFCreator is a lightweight and flexible short video production library",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand All @@ -22,6 +22,8 @@
],
"license": "MIT",
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@ffprobe-installer/ffprobe": "^2.1.2",
"@tweenjs/tween.js": "18.5.0",
"@xsstomy/subsrt": "^1.0.0",
"browser-or-node": "^1.3.0",
Expand Down
2 changes: 2 additions & 0 deletions types/lib/FFCreator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ declare namespace FFCreatorSpace {
*/
static setFFprobePath(path: string): void;

static setFFPath(): void;

/**
* Create new effect and add to effects object
* @param name the new effect name
Expand Down
2 changes: 2 additions & 0 deletions types/lib/FFCreatorCenter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ declare namespace FFCreatorSpace {
*/
setFFprobePath(path: string): void;

setFFPath(): void;

/**
* get task progress by task id
* @param id
Expand Down
2 changes: 2 additions & 0 deletions types/lib/FFmpegUtil.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ declare namespace FFCreatorSpace {

setFFprobePath(path: string): void;

setFFPath(): void;

createCommand(conf?: { threads?: number }): any;

interceptVideo(options: { video: string; ss: string; to: string; output: string }): void;
Expand Down

0 comments on commit f6f2bba

Please sign in to comment.