diff --git a/README.md b/README.md index 4cab99cf..89caac1d 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,17 @@ Disables audio in the output and remove any previously set audio option. ffmpeg('/path/to/file.avi').noAudio(); ``` +#### audioSpeed(): change audio speed + +**Aliases**: `withAudioSpeed()`. + +Speed Up/Down audio + +```js +ffmpeg('/path/to/file.avi').audioSpeed(3); +ffmpeg('/path/to/file.avi').audioSpeed(0.4); +``` + #### audioCodec(codec): set audio codec **Aliases**: `withAudioCodec()`. @@ -339,6 +350,17 @@ This method disables video output and removes any previously set video option. ffmpeg('/path/to/file.avi').noVideo(); ``` +#### videoSpeed(): change video speed + +**Aliases**: `withVideoSpeed()`. + +Speed Up/Down video + +```js +ffmpeg('/path/to/file.avi').videoSpeed(3); +ffmpeg('/path/to/file.avi').videoSpeed(0.4); +``` + #### videoCodec(codec): set video codec **Aliases**: `withVideoCodec()`. diff --git a/lib/options/audio.js b/lib/options/audio.js index 607fdb37..213ba098 100644 --- a/lib/options/audio.js +++ b/lib/options/audio.js @@ -113,6 +113,32 @@ module.exports = function(proto) { }; + /** + * Set audio speed + * + * @method FfmpegCommand#audioSpeed + * @category Output + * @aliases withAudioSpeed,setAudioSpeed + * + * @param {String|Number} audioSpeed The value of the audio speed. + * @return FfmpegCommand + */ + proto.withAudioSpeed = + proto.setAudioSpeed = + proto.audioSpeed = function(audioSpeed) { + if (audioSpeed > 2) { + this._currentOutput.audioFilters('atempo=2'); + return this.audioSpeed(audioSpeed/2); + } else if (audioSpeed < 0.5) { + this._currentOutput.audioFilters('atempo=0.5'); + return this.audioSpeed(audioSpeed/0.5); + } + + this._currentOutput.audioFilters('atempo=' + audioSpeed); + return this; + }; + + /** * Specify custom audio filter(s) * diff --git a/lib/options/videosize.js b/lib/options/videosize.js index b175dcd4..36675c4c 100644 --- a/lib/options/videosize.js +++ b/lib/options/videosize.js @@ -250,6 +250,23 @@ module.exports = function(proto) { }; + /** + * Set video speed + * + * @method FfmpegCommand#videoSpeed + * @category Output + * @aliases withVideoSpeed,setVideoSpeed + * + * @param {String|Number} videoSpeed The value of the video speed. + * @return FfmpegCommand + */ + proto.withVideoSpeed = + proto.setVideoSpeed = + proto.videoSpeed = function(videoSpeed) { + this._currentOutput.sizeFilters('setpts=' + 1/videoSpeed + '*PTS'); + return this; + }; + /** * Enable auto-padding the output *