gifmaker.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var ffmpeg = require('fluent-ffmpeg');
  2. var ffmpegStatic = require('ffmpeg-static');
  3. var path = require('path');
  4. var fs = require('fs');
  5. exports.makewithfilters = function (template, filters) {
  6. //console.log(ffmpegStatic.path);
  7. ffmpeg.setFfmpegPath(ffmpegStatic.path)
  8. template = path.resolve(`templates/${template}`);
  9. // 模板部分处理
  10. if (!fs.existsSync(template)) {
  11. console.log(template)
  12. console.log('模版不存在')
  13. return '模板不存在';
  14. }
  15. // ffmpeg
  16. let proc = ffmpeg(template);
  17. filters = filters || [];
  18. filters = JSON.parse(JSON.stringify(filters));
  19. // 水印添加
  20. filters.push({
  21. filter: 'drawtext',
  22. options: {
  23. 'text': '多玩图库',
  24. 'x': '5',
  25. 'y': '5',
  26. 'fontfile': 'AppleGothic.ttc',
  27. 'fontcolor': 'white',
  28. 'fontsize': '14'
  29. }
  30. });
  31. // filter
  32. filters.forEach((filter) => {
  33. let options = filter.options;
  34. // 字体文件补全
  35. // if (options.hasOwnProperty('fontfile')) {
  36. options.fontfile = path.resolve(`data/fonts/simsun.ttc`);
  37. // }
  38. });
  39. // console.log(filters);
  40. return proc.videoFilters(filters).noAudio()
  41. }
  42. exports.makewithass = function (template, sentences) {
  43. }