execpkg.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. //Use ffmpeg to convert a file named test.mp4 on desktop
  2. console.log("Demo for converting a test.mp4 on Desktop to test.mp3");
  3. var srcVirtual = "user:/Desktop/test.mp4";
  4. //Helper function to get the filepath.Dir of the realpath
  5. function dir(filepath){
  6. filepath = filepath.split("/");
  7. filepath.pop();
  8. return filepath.join("/");
  9. }
  10. //Require ffmpeg package
  11. if (requirepkg("ffmpeg",true)){
  12. //Package required. Get the real path of the file
  13. var srcReal = decodeVirtualPath(srcVirtual);
  14. srcReal = srcReal.split("\\").join("/");
  15. console.log("File real path: " + srcReal);
  16. //Generate the destination filepath (real)
  17. var destReal = dir(srcReal) + "/test.mp3";
  18. console.log("Output file path: " + destReal);
  19. //Convert the real path to the designed path
  20. //If you want to include filepath with space, you must use " instead of '
  21. var results = execpkg("ffmpeg",'-i "' + srcReal + '" "' + destReal + '"');
  22. //Send the CMD output as text to response
  23. sendResp(results);
  24. }else{
  25. sendResp("Failed to require package ffmpeg");
  26. }