gifski.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const child_process_1 = require("child_process");
  4. const temp = require("temp");
  5. const loggers_1 = require("./loggers");
  6. const fs_1 = require("fs");
  7. const logger = loggers_1.getLogger('gifski');
  8. function default_1(data) {
  9. const outputFilePath = temp.path({ suffix: '.gif' });
  10. // temp.track();
  11. try {
  12. const inputFile = temp.openSync();
  13. fs_1.writeSync(inputFile.fd, Buffer.from(data));
  14. fs_1.closeSync(inputFile.fd);
  15. logger.info(`saved video file to ${inputFile.path}, starting gif conversion...`);
  16. const args = [
  17. '--fps',
  18. '12.5',
  19. '--quiet',
  20. '--quality',
  21. '80',
  22. '-o',
  23. outputFilePath,
  24. inputFile.path
  25. ];
  26. logger.info(` gifski ${args.join(' ')}`);
  27. const gifskiInvocation = child_process_1.spawnSync('gifski', args, { encoding: 'utf8', timeout: 90000 });
  28. if (gifskiInvocation.stderr)
  29. throw Error(gifskiInvocation.stderr);
  30. logger.info(`gif conversion succeeded, file path: ${outputFilePath}`);
  31. return fs_1.readFileSync(outputFilePath).buffer;
  32. }
  33. catch (error) {
  34. logger.error('error converting video to gif' + error ? `message: ${error}` : '');
  35. throw Error('error converting video to gif');
  36. }
  37. }
  38. exports.default = default_1;