Permalink
Browse files

Merge pull request #6 from tommedema/timeout2

added optional processing timeout parameter
  • Loading branch information...
2 parents e970def + 24d2e8e commit c87d206d0a94327c2f31cd35b22190f49b4c5f63 @schaermu schaermu committed Jun 13, 2011
Showing with 22 additions and 1 deletion.
  1. +22 −1 lib/fluent-ffmpeg.js
View
@@ -4,7 +4,7 @@ var fs = require('fs'),
exec = require('child_process').exec,
spawn = require('child_process').spawn;
-function FfmpegProcessor(source) {
+function FfmpegProcessor(source, timeout) { //timeout in milliseconds is optional
// check if argument is a stream
var srcstream, srcfile;
if (typeof source === 'object') {
@@ -28,6 +28,7 @@ function FfmpegProcessor(source) {
_nice: {},
inputfile: srcfile,
inputstream: srcstream,
+ timeout: timeout,
video: {},
audio: {},
additional: []
@@ -288,10 +289,20 @@ function FfmpegProcessor(source) {
self.options.inputstream.resume();
self.options.inputstream.pipe(ffmpegProc.stdin, { end: true });
}
+
+ //handle timeout if set
+ var processTimer;
+ if (self.options.timeout) {
+ processTimer = setTimeout(function() {
+ ffmpegProc.kill('SIGKILL');
+ callback(-1, 'timeout');
+ }, self.options.timeout);
+ }
var stdout = '';
var stderr = '';
ffmpegProc.on('exit', function(code) {
+ if (processTimer) clearTimeout(processTimer);
// check if we have to run flvtool2 to update flash video meta data
if (self.options._updateFlvMetadata === true) {
// check if flvtool2 is installed
@@ -348,6 +359,15 @@ function FfmpegProcessor(source) {
self.options.inputstream.resume();
self.options.inputstream.pipe(ffmpegProc.stdin);
}
+
+ //handle timeout if set
+ var processTimer;
+ if (self.options.timeout) {
+ processTimer = setTimeout(function() {
+ ffmpegProc.kill('SIGKILL');
+ callback(-1, 'timeout');
+ }, self.options.timeout);
+ }
var stderr = '';
@@ -356,6 +376,7 @@ function FfmpegProcessor(source) {
});
ffmpegProc.on('exit', function(code) {
+ if (processTimer) clearTimeout(processTimer);
callback(code, stderr);
});

0 comments on commit c87d206

Please sign in to comment.