Permalink
Browse files

Add withAudioFilter/withVideoFilter

  • Loading branch information...
1 parent 56b8560 commit 7ce0fe60bef35214376794b7e5991300cfdf66c2 @njoyard njoyard committed Feb 28, 2014
Showing with 61 additions and 7 deletions.
  1. +9 −0 README.md
  2. +10 −0 lib/fluent-ffmpeg.js
  3. +11 −2 lib/processor.js
  4. +31 −5 test/args.test.js
View
@@ -196,6 +196,15 @@ new FFmpeg({ source: '/path/to/video.avi' })
// Set output format
.toFormat('webm')
+ /** Custom filters **/
+
+ // Add custom audio filters
+ .withAudioFilter('equalizer=f=1000:width_type=h:width=200:g=-10')
+ .withAudioFilter('pan=1:c0=0.9*c0+0.1*c1')
+
+ // Add custom video filters
+ .withVideoFilter('size=iw*1.5:ih/2')
+ .withVideoFilter('drawtext=\'fontfile=FreeSans.ttf:text=Hello\'')
/** Miscellaneous options **/
View
@@ -150,6 +150,11 @@ function FfmpegCommand(args) {
this.options.video.codec = codec;
return this;
};
+ FfmpegCommand.prototype.withVideoFilter = function(filter) {
+ this.options.video.filters = this.options.video.filters || [];
+ this.options.video.filters.push(filter);
+ return this;
+ };
FfmpegCommand.prototype.loop = function(duration) {
this.options.video.loop = true;
if (duration) {
@@ -184,6 +189,11 @@ function FfmpegCommand(args) {
this.options.audio.quality = parseInt(quality, 10);
return this;
};
+ FfmpegCommand.prototype.withAudioFilter = function(filter) {
+ this.options.audio.filters = this.options.audio.filters || [];
+ this.options.audio.filters.push(filter);
+ return this;
+ };
FfmpegCommand.prototype.setStartTime = function(timestamp) {
this.options.starttime = timestamp;
return this;
View
@@ -809,6 +809,10 @@ exports = module.exports = function Processor(command) {
}
}
+ if (this.options.audio.filters) {
+ args.push('-filter:a', this.options.audio.filters.join(','));
+ }
+
// add additional options
if (this.options.additional) {
if (this.options.additional.length > 0) {
@@ -818,12 +822,13 @@ exports = module.exports = function Processor(command) {
}
}
+ var videoFilters = this.options.video.filters || [];
+
if (this.options.video.pad && !this.options.video.skip) {
// we have padding arguments, push
if (this.atLeastVersion(this.metaData.ffmpegversion, '0.7')) {
// padding is not supported ffmpeg < 0.7 (only using legacy commands which were replaced by vfilter calls)
- args.push('-vf');
- args.push('pad=' + this.options.video.pad.w +
+ videoFilters.push('pad=' + this.options.video.pad.w +
':' + this.options.video.pad.h +
':' + this.options.video.pad.x +
':' + this.options.video.pad.y +
@@ -833,6 +838,10 @@ exports = module.exports = function Processor(command) {
}
}
+ if (videoFilters.length) {
+ args.push('-filter:v', videoFilters.join(','));
+ }
+
// add size and output file
if (this.options.video.size && !this.options.video.skip) {
args.push('-s', this.options.video.size);
View
@@ -172,7 +172,7 @@ describe('Command', function() {
if (err) {
done(err);
} else {
- args.indexOf('-vf').should.above(-1);
+ args.indexOf('-filter:v').should.above(-1);
args.indexOf('pad=1024:768:128:0:red').should.above(-1);
done();
}
@@ -187,7 +187,7 @@ describe('Command', function() {
done(err);
} else {
args.indexOf('1280x540').should.above(-1);
- args.indexOf('-vf').should.above(-1);
+ args.indexOf('-filter:v').should.above(-1);
args.indexOf('pad=1280:720:0:90:black').should.above(-1);
done();
}
@@ -201,7 +201,7 @@ describe('Command', function() {
if (err) {
done(err);
} else {
- args.indexOf('-vf').should.above(-1);
+ args.indexOf('-filter:v').should.above(-1);
args.indexOf('pad=640:480:0:60:black').should.above(-1);
done();
}
@@ -216,7 +216,7 @@ describe('Command', function() {
if (err) {
done(err);
} else {
- args.indexOf('-vf').should.above(-1);
+ args.indexOf('-filter:v').should.above(-1);
args.indexOf('pad=640:480:0:60:black').should.above(-1);
done();
}
@@ -232,7 +232,7 @@ describe('Command', function() {
if (err) {
done(err);
} else {
- args.indexOf('-vf').should.above(-1);
+ args.indexOf('-filter:v').should.above(-1);
args.indexOf('pad=640:480:0:60:black').should.above(-1);
done();
}
@@ -299,6 +299,19 @@ describe('Command', function() {
});
});
+ describe('withVideoFilter', function() {
+ it('should apply the video filter argument', function(done) {
+ new Ffmpeg({ source: this.testfile, nolog: true })
+ .withVideoFilter('scale=123:456')
+ .withVideoFilter('pad=1230:4560:100:100:yellow')
+ .getArgs(function(args) {
+ args.indexOf('-filter:v').should.above(-1);
+ args.indexOf('scale=123:456,pad=1230:4560:100:100:yellow').should.above(-1);
+ done();
+ });
+ });
+ })
+
describe('withAudioBitrate', function() {
it('should apply the audio bitrate argument', function(done) {
new Ffmpeg({ source: this.testfile, nolog: true })
@@ -379,6 +392,19 @@ describe('Command', function() {
});
});
+ describe('withAudioFilter', function() {
+ it('should apply the audio filter argument', function(done) {
+ new Ffmpeg({ source: this.testfile, nolog: true })
+ .withAudioFilter('silencedetect=n=-50dB:d=5')
+ .withAudioFilter('volume=0.5')
+ .getArgs(function(args) {
+ args.indexOf('-filter:a').should.above(-1);
+ args.indexOf('silencedetect=n=-50dB:d=5,volume=0.5').should.above(-1);
+ done();
+ });
+ });
+ })
+
describe('withAudioChannels', function() {
it('should apply the audio channels argument', function(done) {
new Ffmpeg({ source: this.testfile, nolog: true })

0 comments on commit 7ce0fe6

Please sign in to comment.