Skip to content

Instantly share code, notes, and snippets.

@manumaticx
Created February 21, 2016 22:49
Show Gist options
  • Save manumaticx/1b57cd48fa4a1a980f04 to your computer and use it in GitHub Desktop.
Save manumaticx/1b57cd48fa4a1a980f04 to your computer and use it in GitHub Desktop.
convert all MP4 files to MOV with ffmpeg and grunt
/**
* This is just a little helper I made when I had to convert a lot of MP4 files.
* Using ffmpeg this works fine but it just needed to be automated. Maybe this isn't the best
* solution, it's quick and dirty but I was happy with its results.
* The grunt script ran overnight to process about a hundred video files.
*/
module.exports = function(grunt) {
var _ = require('underscore');
grunt.registerTask('default', convertVideoFiles);
function convertVideoFiles(){
var done = this.async();
var mp4s = grunt.file.expand({ filter: 'isFile'}, ['**/*.MP4']);
function mp4ToMov(path){
convert(path, function(){
if (_.isEmpty(mp4s)){
done();
} else {
mp4ToMov(mp4s.shift());
}
});
}
mp4ToMov(mp4s.shift());
}
function convert(path, callback){
if (!grunt.file.exists(path)){
console.log(path + ' not found');
callback();
}
var ext = '.' + _.last(path.split('.'));
var mov = path.replace(ext, '.MOV');
grunt.util.spawn({
cmd: "ffmpeg",
args: ['-i', path, mov]
}, function(err, result, code){
if (err){
console.log('ERROR: ' + path);
callback();
}
grunt.file.delete(path);
console.log('converted ' + mov);
callback();
});
}
};
{
"name": "mp4-mov-convert",
"version": "0.1.0",
"description": "mp4 to mov conversion helper for ffmpeg",
"author": "Manuel Lehner",
"license": "MIT",
"devDependencies": {
"grunt": "^0.4.5",
"underscore": "^1.8.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment