Skip to content

Commit

Permalink
implemented batch copying/renaming of captured stopmotion images
Browse files Browse the repository at this point in the history
because of windows
  • Loading branch information
louis-ev committed Jan 3, 2017
1 parent 83d3a74 commit 0613db9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 63 deletions.
149 changes: 88 additions & 61 deletions bin/dodoc-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var slugg = require('slugg');
var merge = require('merge');

var mm = require('marky-mark');
var glob = require('glob')
var pad = require('pad-left');

var ffmpegstatic = require('ffmpeg-static');
var ffmpeg = require('fluent-ffmpeg');
Expand Down Expand Up @@ -150,31 +152,9 @@ var dodocMedia = (function() {

_createThumbnails(pathToFile + dodoc.videoext, newFileName, mediaPath)
.then(function(mediaFolderContent) {

if(newMediaData.mediaData.audioData === undefined) {
resolve(mdata);
}

/*
var audioFile = pathToFile + dodoc.audioext;
var videoFile = pathToFile + dodoc.videoext;
var proc = new ffmpeg()
.addOptions(['-vb 8000k', '-i '+audioFile, '-itsoffset -00:00:01', '-i '+videoFile, '-map 0:0', '-map 1:0'])
// var command = "ffmpeg -i " + audioFile + " -itsoffset -00:00:01 -i " + videoFile + " -map 0:0 -map 1:0 " + mergedFile;
// setup event handlers
.on('end', function() {
dev.log('Successful merge of video+audio track.');
resolve(mdata);
})
.on('error', function(err) {
dev.log('an error happened: ' + err.message);
resolve('couldn\'t create a video animation');
})
// save to file
.save( pathToFile + '_merged' + dodoc.videoext);
*/

}, function(error) {
dev.error('--> Failed to make a thumbnail for a video! Error: ' + error);
resolve(mdata);
Expand All @@ -196,46 +176,59 @@ var dodocMedia = (function() {
var frameRate = newMediaData.frameRate || 4;

var numberOfImagesToProcess = fs.readdirSync(pathToFile).length;
dev.logverbose(`Number of images in to process in ${pathToFile} is ${numberOfImagesToProcess}`);

// ask ffmpeg to make a video from the cache images
var proc = new ffmpeg({ "source" : path.join(pathToFile, '%*.jpeg') })
// using 12 fps
.withFpsInput(frameRate)
.withVideoCodec('libvpx')
.addOptions(['-vb 8000k', '-f webm'])
// setup event handlers
.on('progress', progress => {
var msg = {
"author" : newMediaData.author,
"content" : `${dodoc.lang.stopMotionCompilationProgress} ${progress.frames}/${numberOfImagesToProcess} ${dodoc.lang.imagesAdded}`
};
require('../sockets').notifyUser(msg);
dev.logverbose(`Processing new stopmotion: image ${progress.frames}/${numberOfImagesToProcess}`);
})
.on('end', () => {
dev.log('file has been converted succesfully');
_createMediaMeta( newMediaType, pathToFile, newFileName).then( function( mdata) {
mdata.slugFolderName = slugFolderName;
mdata.slugProjectName = slugProjectName;
mdata.mediaFolderPath = mediaFolder;
_createThumbnails( pathToFile + fileExtension, newFileName, mediaPath).then(function( mediaFolderContent) {
resolve( mdata);
}, error => {
dev.error("Failed to make a thumbnail for a stopmotion! Error: " + error);
resolve( mdata);
dev.logverbose(`Number of images to process in ${pathToFile} is ${numberOfImagesToProcess}`);

_batchCopyToNewFolder(pathToFile)
.then(stopmotionImageSequenceFolderPath => {
// ask ffmpeg to make a video from the cache images
var proc = new ffmpeg()
.input(path.join(stopmotionImageSequenceFolderPath, 'img-%04d.jpeg'))
// using 12 fps
.withFpsInput(frameRate)
.withVideoCodec('libvpx')
.addOptions(['-vb 8000k', '-f webm'])
.output(pathToFile + fileExtension)
// setup event handlers
.on('progress', progress => {
var msg = {
"author" : newMediaData.author,
"content" : `${dodoc.lang.stopMotionCompilationProgress} ${progress.frames}/${numberOfImagesToProcess} ${dodoc.lang.imagesAdded}`
};
require('../sockets').notifyUser(msg);
dev.logverbose(`Processing new stopmotion: image ${progress.frames}/${numberOfImagesToProcess}`);
})
.on('end', () => {
dev.log('file has been converted succesfully');
// remove temp folder with seq images
fs.remove(stopmotionImageSequenceFolderPath);

_createMediaMeta( newMediaType, pathToFile, newFileName).then( function( mdata) {
mdata.slugFolderName = slugFolderName;
mdata.slugProjectName = slugProjectName;
mdata.mediaFolderPath = mediaFolder;
_createThumbnails( pathToFile + fileExtension, newFileName, mediaPath).then(function( mediaFolderContent) {
resolve( mdata);
}, error => {
dev.error("Failed to make a thumbnail for a stopmotion! Error: " + error);
resolve( mdata);
});
}, () => {
reject( 'failed to create meta for stopmotion');
});
}, () => {
reject( 'failed to create meta for stopmotion');
});

})
.on('error', err => {
dev.log('an error happened: ' + err.message);
reject( "couldn't create a stopmotion animation");
})
// save to file
.save( pathToFile + fileExtension);

})

.on('error', function(err, stdout, stderr) {
dev.error('An error happened: ' + err.message);
dev.error('ffmpeg standard output:\n' + stdout);
dev.error('ffmpeg standard error:\n' + stderr);
reject( "couldn't create a stopmotion animation");
})

// save to file
.run();
});

break;
case 'audio':
var mediaPath = _getMediaPath( slugFolderName, slugProjectName, mediaFolder);
Expand Down Expand Up @@ -554,6 +547,40 @@ var dodocMedia = (function() {
return cleanMediaName;
}

function _batchCopyToNewFolder(pathToFile) {
return new Promise(function(resolve, reject) {
dev.logfunction("COMMON — _batchCopyToNewFolder");
// create a folder at pathToFile
var seqImageFolder = path.join(pathToFile, 'seq');
fs.ensureDirSync(seqImageFolder);

// copy each images there with a name following img-%04d.jpeg
glob(pathToFile + '/*.jpeg', [], function (er, files) {

let processed = 0, index = 0;
files.forEach(function(file) {
// todo : passer en async et check à la fin

fs.copy(file, path.join(seqImageFolder, 'img-' + pad(index, 4, '0') + '.jpeg'), function (err) {
if(err) {
dev.error('failed to copy: ' + err);
reject(err);
}
processed++;
if(processed === files.length) {
// resolve path to this new folder
resolve(seqImageFolder);
dev.log("Stopmotion - renaming step : " + processed + " files processed out of " + files.length);
}
});

index++;

});
});
});
}

return API;
})();

Expand Down
2 changes: 1 addition & 1 deletion client/css/style.min.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dodoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ if( lang === 'fr') {
"enableLogToFile" : "mode debug",

"creditADC" : "do•doc est un projet développé par l’Atelier des Chercheurs",
"websiteofADC" : "Site de l’Atelier des Chercheurs",

"currentVideoResolutionIs" : "Résolution actuelle : ",
"videoStreamCouldntBeStartedTryChangingRes" : "Le flux vidéo n’a pas pu être démarré.\nEssayez de modifier la résolution dans le panneau de droite.",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"ftp": "^0.3.10",
"ftp-deploy": "^1.1.0",
"glob": "*",
"glob-electron": "^0.1.0",
"gm": "^1.22.0",
"gulp-util": "^3.0.7",
"html-pdf": "^2.1.0",
Expand All @@ -65,6 +66,7 @@
"merge": "^1.2.0",
"moment": "^2.12.0",
"node-localstorage": "^1.3.0",
"pad-left": "^2.1.0",
"path": "^0.12.7",
"phantom": "^3.2.0",
"sharp": "^0.17.0",
Expand Down

0 comments on commit 0613db9

Please sign in to comment.