ffmpeg.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. //Ok. Proceed with conversion
  31. var succ = ffmpeg.convert(INPUT, OUTPUT);
  32. if (succ){
  33. sendJSONResp(JSON.stringify("ok"));
  34. }else{
  35. sendJSONResp(JSON.stringify({
  36. "error":"ffmpeg reports a conversion error"
  37. }));
  38. }
  39. }
  40. //Run the main conversion logic
  41. main();