Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fluent-ffmpeg

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluent-ffmpeg - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

33

lib/calculate.js
exports = module.exports = function Calculate(command) {
this._calculatePadding = function(data) {
if (data.aspect) {
if (data.video.aspect) {
var newaspect;

@@ -20,7 +20,7 @@ // check if the aspect ratio has changed

if (!this.options.video.width && !this.options.video.height) {
this.options.video.width = data.resolution.w;
this.options.video.height = data.resolution.h;
this.options.video.width = data.video.resolution.w;
this.options.video.height = data.video.resolution.h;
}
if (!_aspectIsEqual(data.aspect, newaspect)) {
if (!_aspectIsEqual(data.video.aspectString, newaspect)) {
var ardata = newaspect.toAspectRatio();

@@ -86,9 +86,12 @@

var w, h;
if (!data.video.resolution)
throw new Error('could not determine video resolution, check your ffmpeg setup');
if (fixedWidth && fixedWidth.length > 0) {
// calculate height of output
if (!data.resolution.w)
if (!data.video.resolution.w)
throw new Error('could not determine width of source video, aborting execution');
var ratio = data.resolution.w / parseInt(fixedWidth[1]);
var ratio = data.video.resolution.w / parseInt(fixedWidth[1]);
// if we have an aspect ratio target set, calculate new size using AR

@@ -106,10 +109,10 @@ if (this.options.video.aspect != undefined) {

w = parseInt(fixedWidth[1]);
h = Math.round(data.resolution.h / ratio);
h = Math.round(data.video.resolution.h / ratio);
}
} else if (fixedHeight && fixedHeight.length > 0) {
// calculate width of output
if (!data.resolution.h)
if (!data.video.resolution.h)
throw new Error('could not determine height of source video, aborting execution');
var ratio = data.resolution.h / parseInt(fixedHeight[1]);
var ratio = data.video.resolution.h / parseInt(fixedHeight[1]);

@@ -127,3 +130,3 @@ // if we have an aspect ratio target set, calculate new size using AR

} else {
w = Math.round(data.resolution.w / ratio);
w = Math.round(data.video.resolution.w / ratio);
h = parseInt(fixedHeight[1]);

@@ -133,8 +136,8 @@ }

// calculate both height and width of output
if (!data.resolution.w || !data.resolution.h)
if (!data.video.resolution.w || !data.video.resolution.h)
throw new Error('could not determine resolution of source video, aborting execution');
var ratio = parseInt(percentRatio[1]) / 100;
w = Math.round(data.resolution.w * ratio);
h = Math.round(data.resolution.h * ratio);
w = Math.round(data.video.resolution.w * ratio);
h = Math.round(data.video.resolution.h * ratio);
} else {

@@ -141,0 +144,0 @@ throw new Error('could not determine type of size string, aborting execution');

@@ -37,3 +37,5 @@ var fs = require('fs'),

audio: {},
additional: []
additional: [],
informInputAudioCodec: null,
informInputVideoCodec: null
};

@@ -170,3 +172,7 @@

return this;
};
};
FfmpegCommand.prototype.onCodecData = function(callback) {
this.options.onCodecData = callback;
return this;
};

@@ -173,0 +179,0 @@ // private methods

@@ -33,3 +33,4 @@ var exec = require('child_process').exec;

var is_synched = (/start: 0.000000/.exec(stderr) != null);
var rotate = /rotate[\s]+:[\s]([\d]{2,3})/.exec(stderr);
// build return object

@@ -48,2 +49,3 @@ var ret = {

},
rotate: (rotate && rotate.length > 1) ? parseInt(rotate[1]) : 0,
fps: (fps && fps.length > 1) ? parseFloat(fps[1]) : 0.0,

@@ -79,8 +81,10 @@ stream: (video_stream && video_stream.length > 1) ? parseFloat(video_stream[1]) : 0.0

// save aspect ratio for auto-padding
ret.video.aspectString = aspect[1];
if (aspect && aspect.length > 0) {
var n = aspect[1].split(":");
ret.video.aspect = parseFloat((parseInt(n[0]) / parseInt(n[1])).toFixed(2));
ret.video.aspect = parseFloat((parseInt(n[0]) / parseInt(n[1])).toFixed(2));
} else {
if(ret.video.resolution.w != 0) {
ret.video.aspect = parseFloat((ret.video.resolution.w / ret.video.resolution.h).toFixed(2));
ret.video.aspect = parseFloat((ret.video.resolution.w / ret.video.resolution.h).toFixed(2));
} else {

@@ -87,0 +91,0 @@ ret.video.aspect = 0.0;

@@ -11,3 +11,11 @@ var fs = require('fs'),

this.E_PROCESSTIMEOUT = -99;
this._codecDataAlreadySent = false;
this._determineFfmpegPath = function() {
if (process.env.FFMPEG_PATH) {
return process.env.FFMPEG_PATH;
}
return 'ffmpeg';
}
this.saveToFile = function(targetfile, callback) {

@@ -71,2 +79,3 @@

stderr += data;
if (self.options.onCodecData) self._checkStdErrForCodec(stderr);
});

@@ -92,3 +101,4 @@ }

// start conversion of file using spawn
var ffmpegProc = self._spawnProcess(args, { customFds: [-1, stream.fd, -1] });
var ffmpegProc = self._spawnProcess(args);
if (self.options.inputstream) {

@@ -114,2 +124,3 @@ // pump input stream to stdin

stderr += data;
if (self.options.onCodecData) self._checkStdErrForCodec(stderr);
});

@@ -172,3 +183,3 @@

exec(process.env.FFMPEG_PATH || 'ffmpeg' + ' ' + tnArgs.join(' '), callback);
exec(this._determineFfmpegPath() + ' ' + tnArgs.join(' '), callback);
}

@@ -195,3 +206,3 @@

// check target folder
if (!path.existsSync(folder)) {
if (!fs.existsSync(folder)) {
fs.mkdir(folder, '0755', function(err) {

@@ -248,3 +259,3 @@ if (err !== null) {

var target = Meta.escapedPath(folder + '/tn_' + offset + 's.jpg');
var input = Meta.escapedPath(this.options.inputfile);
var input = Meta.escapedPath(self.options.inputfile);

@@ -268,5 +279,5 @@

// execute ffmpeg through nice
exec('nice --adjustment="' + self.options._nice.level + '" ffmpeg ' + tnArgs.join(' '), taskcallback);
exec('nice -n="' + self.options._nice.level + '" ' + self._determineFfmpegPath() + ' ' + tnArgs.join(' '), taskcallback);
} else {
exec(process.env.FFMPEG_PATH || 'ffmpeg' + ' ' + tnArgs.join(' '), taskcallback);
exec(self._determineFfmpegPath() + ' ' + tnArgs.join(' '), taskcallback);
}

@@ -285,4 +296,23 @@ },

this._checkStdErrForCodec = function(stderrString) {
var audio = /Audio\: ([^,]+)/.exec(stderrString);
var video = /Video\: ([^,]+)/.exec(stderrString);
var codecObject = { audio: '', video: '' };
if (audio && audio.length > 1) {
codecObject.audio = audio[1];
}
if (video && video.length > 1) {
codecObject.video = video[1];
}
var codecInfoPassed = /Press \[q\] to stop/.exec(stderrString);
if (codecInfoPassed) {
this.options.onCodecData(codecObject);
this.options.onCodecData = null;
}
};
this._spawnProcess = function(args, options) {
var retProc = spawn(process.env.FFMPEG_PATH || 'ffmpeg', args, options);
var retProc = spawn(this._determineFfmpegPath(), args, options);
if (this.options._nice.level) {

@@ -295,2 +325,3 @@ var niceLvl = (this.options._nice.level > 0 ? '+' + this.options._nice.level : this.options._nice.level);

}
if (retProc.stderr) retProc.stderr.setEncoding('utf8');
return retProc;

@@ -297,0 +328,0 @@ };

{
"name": "fluent-ffmpeg",
"version": "0.1.1",
"version": "0.2.0",
"description": "A fluent API to FFMPEG (http://www.ffmpeg.org)",

@@ -12,4 +12,5 @@ "keywords": [ "ffmpeg" ],

"repository": "git://github.com/schaermu/node-fluent-ffmpeg.git",
"devDependencies": { "nodeunit": ">= 0.6.4" },
"engines" : { "node" : ">=0.4.0" },
"main": "./lib/fluent-ffmpeg"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc