worker-asm.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. importScripts('ffmpeg-all-codecs.js');
  2. var now = Date.now;
  3. function print(text) {
  4. postMessage({
  5. 'type' : 'stdout',
  6. 'data' : text
  7. });
  8. }
  9. onmessage = function(event) {
  10. var message = event.data;
  11. if (message.type === "command") {
  12. var Module = {
  13. print: print,
  14. printErr: print,
  15. files: message.files || [],
  16. arguments: message.arguments || [],
  17. TOTAL_MEMORY: 268435456
  18. // Can play around with this option - must be a power of 2
  19. // TOTAL_MEMORY: 268435456
  20. };
  21. postMessage({
  22. 'type' : 'start',
  23. 'data' : Module.arguments.join(" ")
  24. });
  25. postMessage({
  26. 'type' : 'stdout',
  27. 'data' : 'Received command: ' +
  28. Module.arguments.join(" ") +
  29. ((Module.TOTAL_MEMORY) ? ". Processing with " + Module.TOTAL_MEMORY + " bits." : "")
  30. });
  31. var time = now();
  32. var result = ffmpeg_run(Module);
  33. var totalTime = now() - time;
  34. postMessage({
  35. 'type' : 'stdout',
  36. 'data' : 'Finished processing (took ' + totalTime + 'ms)'
  37. });
  38. postMessage({
  39. 'type' : 'done',
  40. 'data' : result,
  41. 'time' : totalTime
  42. });
  43. }
  44. };
  45. postMessage({
  46. 'type' : 'ready'
  47. });