ffmpeg.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. FFmpeg.js
  3. ArozOS FFMPEG FACTORY conversion backend
  4. This script is designed to do server side conversion only.
  5. For the client-side conversion function, see
  6. ffmpeg.wasm and the related files for more information.
  7. Required parameters
  8. INPUT (input filepath)
  9. OUTPUT (output filepath)
  10. COMPRESS (optional, output compression)
  11. */
  12. requirelib("filelib");
  13. requirelib("ffmpeg");
  14. function main(){
  15. //Check if the input and output are valid
  16. if (typeof(INPUT) == "undefined" || typeof(OUTPUT) == "undefined"){
  17. //Invalid input or output
  18. sendJSONResp(JSON.stringify({
  19. "error":"invalid INTPUT or OUTPUT given"
  20. }));
  21. return;
  22. }
  23. //Check if input exists
  24. if (!filelib.fileExists(INPUT)){
  25. sendJSONResp(JSON.stringify({
  26. "error":"INTPUT file not exists"
  27. }));
  28. return;
  29. }
  30. var compressionRate = 0;
  31. if (typeof(COMP) != "undefined"){
  32. compressionRate = parseInt(COMP)
  33. }
  34. console.log("Using compression rate " + compressionRate);
  35. //Ok. Proceed with conversion
  36. var succ = ffmpeg.convert(INPUT, OUTPUT, compressionRate);
  37. if (succ){
  38. sendJSONResp(JSON.stringify("ok"));
  39. }else{
  40. sendJSONResp(JSON.stringify({
  41. "error":"ffmpeg reports a conversion error"
  42. }));
  43. }
  44. }
  45. //Run the main conversion logic
  46. main();