Skip to content

Commit

Permalink
removed uuid dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
eralpkaraduman committed Dec 19, 2012
1 parent 2b1b484 commit baf569b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
18 changes: 11 additions & 7 deletions examples/mergeVideos.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ var ffmpeg = require('../index');
ffmpeg -i source.mp4 -qscale:v 1 intermediate2.mpg
ffmpeg -i concat:"intermediate1.mpg|intermediate2.mpg" -c copy intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -qscale:v 2 output.mp4
Create temporary .mpg files for each video and deletes them after merge is completed.
These files are created by filename pattern like [videoFilename.ext].temp.mpg [outputFilename.ext].temp.merged.mp4
*/

var firstFile = "title.mp4";
var secondFile = "source.mp4"
var outPath = "out.mp4"
var tempFolderPath = "myTempFolder/"; // requires a temp folder to store intermediate videos, deletes them after merge is completed.
var secondFile = "source.mp4";
var thirdFile = "third.mov";
var outPath = "out.mp4";

var proc = new ffmpeg({source:firstFile,nolog:true})
.mergeAdd(secondFile)
//.mergeAdd(thirdFile)
.mergeAdd(thirdFile)
//.mergeAdd(fourthFile)
.mergeToFile(outPath,tempFolderPath,function(){
console.log('files has been merged succesfully');
});
//.mergeAdd(...)
.mergeToFile(outPath,function(){
console.log('files have been merged successfully');
});
23 changes: 10 additions & 13 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ var fs = require('fs'),
os = require('os').platform(),
exec = require('child_process').exec,
spawn = require('child_process').spawn,
Registry = require('./registry'),
uuid = require('node-uuid'),
Registry = require('./registry');

exports = module.exports = function Processor(command) {
// constant for timeout checks
Expand Down Expand Up @@ -106,7 +105,7 @@ exports = module.exports = function Processor(command) {
});
};

this.mergeToFile = function(targetfile,tempFolderPath,callback){
this.mergeToFile = function(targetfile,callback){
this.options.outputfile = targetfile;
var self = this;
var options = this.options;
Expand All @@ -118,26 +117,24 @@ exports = module.exports = function Processor(command) {

// creates intermediate copies of each video.
var makeIntermediateFile = function(_mergeSource,_callback){
var fname = uuid.v1()+".mpg";
var fullP = self.escapedPath(path.join(tempFolderPath, fname), true);
var fname = _mergeSource+".temp.mpg";
var command = [
self.ffmpegPath,
[
'-i', _mergeSource,
'-qscale:v',1,
fullP
fname
].join(' ')
];
exec(command.join(' '),function(err, stdout, stderr) {
if(err)throw err;
_callback(fullP);
_callback(fname);
});
};

// concat all created intermediate copies
var concatIntermediates = function(intermediatesList,_callback){
var fname = uuid.v1()+".mpg";
var fullP = self.escapedPath(path.join(tempFolderPath, fname), true);
var concatIntermediates = function(target,intermediatesList,_callback){
var fname = target+".temp.merged.mpg";

// unescape paths
for(var i=0; i<intermediatesList.length; i++){
Expand All @@ -150,12 +147,12 @@ exports = module.exports = function Processor(command) {
'-loglevel','panic', //Generetes too much muxing warnings and fills default buffer of exec. This is to ignore them.
'-i', 'concat:"'+intermediatesList.join("|")+'"',
'-c',"copy",
fullP
fname
].join(' ')
];
exec(command.join(' '), function(err, stdout, stderr) {
if(err)throw err;
_callback(fullP);
_callback(fname);
});
};

Expand Down Expand Up @@ -203,7 +200,7 @@ exports = module.exports = function Processor(command) {
})
},function(err){
if(err)throw err;
concatIntermediates(intermediateFiles,function(concatResult){
concatIntermediates(targetfile,intermediateFiles,function(concatResult){
if(!concatResult)throw new Error("Invalid concat result file");
quantizeConcat(concatResult,intermediateFiles.length,function(){
intermediateFiles.push(concatResult); // add concatResult to intermediates list so it can be deleted too.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"repository": "git://github.com/schaermu/node-fluent-ffmpeg.git",
"devDependencies": { "mocha": "latest", "should": "latest" },
"dependencies": { "winston": ">=0.5.10","node-uuid":"1.4.0" },
"dependencies": { "winston": ">=0.5.10" },
"engines" : { "node" : ">=0.5.0" },
"main": "index",
"scripts": {
Expand Down

0 comments on commit baf569b

Please sign in to comment.