ffmpeg_convert.job.agi 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. FFmpeg convert - the job half
  3. Converts one video on whichever node the scheduler picked. The launcher
  4. asks for the "ffmpeg" capability, so this only ever runs on a node that
  5. has ffmpeg installed, and lists the input file, so a node that already
  6. holds a copy of it is preferred and the video does not cross the network
  7. twice.
  8. The ffmpeg library reads the input and writes the output through the
  9. cluster drive, so cluster:/ paths work here exactly like user:/ paths.
  10. args:
  11. input default "cluster:/demo.mp4"
  12. output default "cluster:/demo.webm" (the extension picks the format)
  13. */
  14. requirelib("filelib");
  15. function run(job) {
  16. var args = job.args || {};
  17. var input = args.input || "cluster:/demo.mp4";
  18. var output = args.output || "cluster:/demo.webm";
  19. //The scheduler already checked for ffmpeg, but a node can lose it
  20. if (!requirelib("ffmpeg")) {
  21. throw new Error("ffmpeg is not available on this node");
  22. }
  23. if (!filelib.fileExists(input)) {
  24. throw new Error("input file not found: " + input);
  25. }
  26. job.log("Converting " + input + " to " + output + " on node " + job.node);
  27. job.progress(0.05);
  28. var started = Date.now();
  29. var ok = ffmpeg.convert(input, output);
  30. if (!ok) {
  31. throw new Error("ffmpeg could not convert " + input);
  32. }
  33. job.progress(1);
  34. job.log("Done");
  35. return {
  36. input: input,
  37. inputBytes: filelib.filesize(input),
  38. output: output,
  39. outputBytes: filelib.filesize(output),
  40. convertedOn: job.node,
  41. seconds: Math.round((Date.now() - started) / 100) / 10
  42. };
  43. }