filelist.js 663 B

12345678910111213141516171819202122
  1. var fs = require('fs');//引用文件系统模块
  2. var ffmpeg = require('fluent-ffmpeg');
  3. let dir = "/Users/john/Desktop/video3";
  4. let newDir = "/Users/john/Desktop/videoNew";
  5. var files = fs.readdirSync(dir);
  6. console.info(files.length)
  7. files.forEach(function (item, index) {
  8. ffmpeg(dir+"/"+item)
  9. .format("mp4")
  10. .videoCodec('libx264')
  11. .size('100%')
  12. .on('end', function() {
  13. console.log('【'+item+'】','file has been converted succesfully');
  14. })
  15. .on('error', function(err) {
  16. console.log('【'+item+'】','an error happened: ' + err.message);
  17. })
  18. .save(newDir+"/"+item);
  19. })