Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new functional: speed Up/Down video and audio #785

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down Expand Up @@ -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()`.
Expand Down
26 changes: 26 additions & 0 deletions lib/options/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down
17 changes: 17 additions & 0 deletions lib/options/videosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down