var ffmpeg = require('fluent-ffmpeg');
var path = require("path");
var config = require("config");

var TranscodeJobManager = {
	counter: 0,
	running: false,
	jobs: [],
	maxJobs: 1,
	transcode: function(jobConfig) {
		var self = this;
		var fullPath = path.join(config.mythbackend.recordings.path, jobConfig.pathname);
		var outputFilename = makeOutputFilename(jobConfig);
		var outputPath = path.join(config.clips.path, outputFilename);
		console.log(fullPath);
console.log(jobConfig.offset);
console.log(jobConfig.duration);
console.log(outputPath);
		ffmpeg(fullPath).seekInput(jobConfig.offset).duration(jobConfig.duration).audioCodec("aac").videoCodec("libx264").on("end", function() {
			console.log('done with ' + outputPath);
			self.running = false;
			self.runJob();
		}).on("error", function(err) {
			console.log(err);	
		}).save(outputPath);;
	},
	runJob: function() {
		if(this.jobs.length>0 && !this.running) { 
			var job = this.jobs.shift();
			this.running = true;
			this.transcode(job);
		}
		else {
			console.log('all jobs done');
		}
	},
	startJob: function(jobConfig, callback) {
		this.counter++;
		jobConfig.id = this.counter;
		this.jobs.push(jobConfig);
		this.runJob();
		callback(null, {"id":this.counter});
	}
};

function makeOutputFilename(jobConfig) {
	var filename = jobConfig.title.split(" ").join("_") + "-" + jobConfig.starttime + "+" + jobConfig.offset + "+" + jobConfig.duration + ".mp4";
	return filename;
}

module.exports = TranscodeJobManager;

@@ -91,16 +91,44 @@
 onfig%22);
+%0Avar uuid = require(%22uuid%22);
 %0A%0Avar Tr
@@ -463,122 +463,8 @@
 e);%0A
-%09%09console.log(fullPath);%0Aconsole.log(jobConfig.offset);%0Aconsole.log(jobConfig.duration);%0Aconsole.log(outputPath);%0A
 %09%09ff
@@ -575,16 +575,42 @@
 bx264%22).
+videoBitrate(10000, true).
 on(%22end%22
@@ -1072,28 +1072,25 @@
 ig.id = 
-this.counter
+uuid.v4()
 ;%0A%09%09this
@@ -1152,28 +1152,28 @@
 , %7B%22id%22:
-this.counter
+jobConfig.id
 %7D);%0A%09%7D%0A%7D
@@ -1216,16 +1216,51 @@
 nfig) %7B%0A
+%09return jobConfig.id + %22.mp4%22;%0A%09/*%0A
 %09var fil
@@ -1394,16 +1394,16 @@
 %22.mp4%22;%0A
-
 %09return 
@@ -1412,16 +1412,20 @@
 lename;%0A
+%09*/%0A
 %7D%0A%0Amodul

use uuid for a good time