@@ -0,0 +1,94 @@
1+// doc missing, dog ate it
2+
3+var path = require('path'),
4+ exec = require('child_process').exec;
5+
6+exports.command = function (input, audio, video, format, output, callback) {
7+ path.exists(input, function (exists) {
8+ if (exists) {
9+ var command = 'ffmpeg -i '+ input +' ';
10+
11+ if (typeof audio === 'object') {
12+ for (flag in audio) {
13+ command += '-'+ flag +' '+ audio[flag] +' ';
14+ }
15+ }
16+
17+ if (typeof video === 'object') {
18+ for (flag in video) {
19+ var value = video[flag];
20+
21+ if (flag === 'vpre' && typeof value === 'object') {
22+ value.forEach(function (preset) {
23+ command += '-vpre '+ preset +' ';
24+ });
25+ }
26+ else if (typeof value === 'string') {
27+ command += '-'+ flag +' '+ value +' ';
28+ }
29+ else
30+ throw new TypeError('Presets must be a string or an array of strings.');
31+ }
32+ }
33+
34+ if (typeof format === 'object' &&
35+ typeof format.width === 'string' &&
36+ typeof format.height === 'string') {
37+
38+ command += '-s '+ format.width +'x'+ format.height +' ';
39+ }
40+
41+ if (typeof output === 'string') {
42+ command += output;
43+ }
44+ else
45+ throw new SyntaxError('Output must be a fileName.containerFormat: '+ output);
46+
47+ exec(command , function (error, stdout, stderr) {
48+ if (error)
49+ throw new Error('ffmpeg didn\'t finish successfully: '+ stderr);
50+ else
51+ callback();
52+ });
53+ }
54+ else
55+ throw new ReferenceError('File not found: '+ input);
56+ });
57+}
58+
59+exports.toMp4 = function (input, format, callback) {
60+
61+ var output = path.dirname(input) +'/'+
62+ path.basename(input, path.extname(input)) +'.mp4';
63+
64+ this.command(input, {
65+ 'acodec': 'libfaac',
66+ 'ab': '128k',
67+ 'ar': '41000'
68+ }, {
69+ 'vcodec': 'libx264',
70+ 'vpre': ['slow', 'baseline'],
71+ 'r': '25'
72+ }, format, output, callback);
73+}
74+
75+exports.toOgg = function(input, format, callback) {
76+ var output = path.dirname(input) +'/'+
77+ path.basename(input, path.extname(input)) +'.ogg';
78+
79+ this.command(input, {
80+ 'acodec': 'libvorbis',
81+ 'ab': '128k',
82+ 'ar': '41000'
83+ }, {
84+ 'vcodec': 'libtheora',
85+ 'r': '25'
86+ }, format, output, callback);
87+}
88+
89+
90+
91+
92+
93+
94+