|
@@ -0,0 +1,22 @@
|
|
|
|
+var fs = require('fs');//引用文件系统模块
|
|
|
|
+var ffmpeg = require('fluent-ffmpeg');
|
|
|
|
+
|
|
|
|
+let dir = "/Users/john/Desktop/video3";
|
|
|
|
+let newDir = "/Users/john/Desktop/videoNew";
|
|
|
|
+
|
|
|
|
+var files = fs.readdirSync(dir);
|
|
|
|
+console.info(files.length)
|
|
|
|
+
|
|
|
|
+files.forEach(function (item, index) {
|
|
|
|
+ ffmpeg(dir+"/"+item)
|
|
|
|
+ .format("mp4")
|
|
|
|
+ .videoCodec('libx264')
|
|
|
|
+ .size('100%')
|
|
|
|
+ .on('end', function() {
|
|
|
|
+ console.log('【'+item+'】','file has been converted succesfully');
|
|
|
|
+ })
|
|
|
|
+ .on('error', function(err) {
|
|
|
|
+ console.log('【'+item+'】','an error happened: ' + err.message);
|
|
|
|
+ })
|
|
|
|
+ .save(newDir+"/"+item);
|
|
|
|
+})
|