lib/utils.js
function(command, stderrLine, codecsObject) {
    var inputPattern = /Input #[0-9]+, ([^ ]+),/;
    var durPattern = /Duration\: ([^,]+)/;
    var audioPattern = /Audio\: (.*)/;
    var videoPattern = /Video\: (.*)/;

    if (!('inputStack' in codecsObject)) {
      codecsObject.inputStack = [];
      codecsObject.inputIndex = -1;
      codecsObject.inInput = false;
    }

    var inputStack = codecsObject.inputStack;
    var inputIndex = codecsObject.inputIndex;
    var inInput = codecsObject.inInput;

    var format, dur, audio, video;

    if (format = stderrLine.match(inputPattern)) {
      inInput = codecsObject.inInput = true;
      inputIndex = codecsObject.inputIndex = codecsObject.inputIndex + 1;

      inputStack[inputIndex] = { format: format[1], audio: '', video: '', duration: '' };
    } else if (inInput && (dur = stderrLine.match(durPattern))) {
      inputStack[inputIndex].duration = dur[1];
    } else if (inInput && (audio = stderrLine.match(audioPattern))) {
      audio = audio[1].split(', ');
      inputStack[inputIndex].audio = audio[0];
      inputStack[inputIndex].audio_details = audio;
    } else if (inInput && (video = stderrLine.match(videoPattern))) {
      video = video[1].split(', ');
      inputStack[inputIndex].video = video[0];
      inputStack[inputIndex].video_details = video;
    } else if (/Output #\d+/.test(stderrLine)) {
      inInput = codecsObject.inInput = false;
    } else if (/Stream mapping:|Press (\[q\]|ctrl-c) to stop/.test(stderrLine)) {
      command.emit.apply(command, ['codecData'].concat(inputStack));
      return true;
    }

    return false;
  }
function(command, stderrLine, codecsObject) {
    var inputPattern = /Input #[0-9]+, ([^ ]+),/;
    var durPattern = /Duration\: ([^,]+)/;
    var audioPattern = /Audio\: (.*)/;
    var videoPattern = /Video\: (.*)/;

    if (!('inputStack' in codecsObject)) {
      codecsObject.inputStack = [];
      codecsObject.inputIndex = -1;
      codecsObject.inInput = false;
    }

    var inputStack = codecsObject.inputStack;
    var inputIndex = codecsObject.inputIndex;
    var inInput = codecsObject.inInput;

    var format, dur, audio, video;

    if (format = stderrLine.match(inputPattern)) {
      inInput = codecsObject.inInput = true;
      inputIndex = codecsObject.inputIndex = codecsObject.inputIndex + 1;

      inputStack[inputIndex] = { format: format[1], audio: '', video: '', duration: '' };
    } else if (inInput && (dur = stderrLine.match(durPattern))) {
      inputStack[inputIndex].duration = dur[1];
    } else if (inInput && (audio = stderrLine.match(audioPattern))) {
      audio = audio[1].split(', ');
      inputStack[inputIndex].audio = audio[0];
      inputStack[inputIndex].audio_details = audio;
    } else if (inInput && (video = stderrLine.match(videoPattern))) {
      video = video[1].split(', ');
      inputStack[inputIndex].video = video[0];
      inputStack[inputIndex].video_details = video;
    } else if (/Output #\d+/.test(stderrLine)) {
      inInput = codecsObject.inInput = false;
    } else if (/Stream mapping:|Press (\[q\]|ctrl-c) to stop/.test(stderrLine)) {
      command.emit.apply(command, ['codecData'].concat(inputStack));
      return true;
    }

    return false;
  }
function ( command , stderrLine , codecsObject ) { var inputPattern = / Input #[0-9]+, ([^ ]+), / ; var durPattern = / Duration\: ([^,]+) / ; var audioPattern = / Audio\: (.*) / ; var videoPattern = / Video\: (.*) / ; if ( ! ( 'inputStack' in codecsObject ) ) { codecsObject . inputStack = [ ] ; codecsObject . inputIndex = - 1 ; codecsObject . inInput = false ; } var inputStack = codecsObject . inputStack ; var inputIndex = codecsObject . inputIndex ; var inInput = codecsObject . inInput ; var format , dur , audio , video ; if ( format = stderrLine . match ( inputPattern ) ) { inInput = codecsObject . inInput = true ; inputIndex = codecsObject . inputIndex = codecsObject . inputIndex + 1 ; inputStack [ inputIndex ] = { format : format [ 1 ] , audio : '' , video : '' , duration : '' } ; } else if ( inInput && ( dur = stderrLine . match ( durPattern ) ) ) { inputStack [ inputIndex ] . duration = dur [ 1 ] ; } else if ( inInput && ( audio = stderrLine . match ( audioPattern ) ) ) { audio = audio [ 1 ] . split ( ', ' ) ; inputStack [ inputIndex ] . audio = audio [ 0 ] ; inputStack [ inputIndex ] . audio_details = audio ; } else if ( inInput && ( video = stderrLine . match ( videoPattern ) ) ) { video = video [ 1 ] . split ( ', ' ) ; inputStack [ inputIndex ] . video = video [ 0 ] ; inputStack [ inputIndex ] . video_details = video ; } else if ( / Output #\d+ / . test ( stderrLine ) ) { inInput = codecsObject . inInput = false ; } else if ( / Stream mapping:|Press (\[q\]|ctrl-c) to stop / . test ( stderrLine ) ) { command . emit . apply ( command , [ 'codecData' ] . concat ( inputStack ) ) ; return true ; } return false ; }
Extract codec data from ffmpeg stderr and emit 'codecData' event if appropriate
Call it with an initially empty codec object once with each line of stderr output until it returns true

@param {FfmpegCommand} command event emitter
@param {String} stderrLine ffmpeg stderr output line
@param {Object} codecObject object used to accumulate codec data between calls
@return {Boolean} true if codec data is complete (and event was emitted), false otherwise
@private
Extract codec data from ffmpeg stderr and emit codecData event if appropriate Call it with an initially empty codec object once with each line of stderr output until it returns true