schaermu/node-fluent-ffmpeg — pull request #204 by njoyard (2014-02-22 09:16:23+00:00)
Title: Inherit from EventEmitter and add events to clean up API

This pull request makes `FfmpegCommand` inherit from `EventEmitter` and implements the following events:
* `start`: replaces `onStart`, emitted when starting ffmpeg with the full command line as an argument
* `progress`: replaces `onProgress`, emitted with progress data
* `codecData`: replaces `onCodecData`, emitted with input codec information
* `end`: called with ffmpegs stdout and stderr data when the job is finished, replaces callbacks to `saveToFile`, `mergeToFile`, `writeToStream` and `takeScreenshots`
* `error`: called when an error occurs, also replaces callbacks to `saveToFile`, `mergeToFile`, `writeToStream` and `takeScreenshots`

The old API is still supported and correctly wires callbacks to the proper events, but issues deprecation warnings.

I also updated the test suite to use events instead of callbacks, and cleaned up some error cases (parts of the code threw errors, which are now correctly reported by emitting an `error` event).

```javascript
ffmpeg({ source: '/path/to/file.mp4' })
.on('progress', function(data) {
console.log(data.percent + '% done');
})
.on('error', function(err) {
console.log('Encoding failed: ' + err.message);
})
.on('end', function(stdout, stderr) {
console.log('Encoding finished');
})
.saveToFile('/path/to/output.avi');

ffmpeg({ source: '/path/to/file.mp4' })
.on('error', function(err) {
console.log('Screenshots failed: ' + err.message);
})
.on('end', function(names) {
console.log('Created screenshots ' + names.join(', '));
})
.takeScreenshots({ count: 4 });
```