Guest User

Untitled

a guest
Oct 17th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. const fs = require('fs');
  2.  
  3. fifo = fs.createReadStream(process.argv[2], { highWaterMark: 4*1024**2, });
  4.  
  5. let t0 = Date.now();
  6. fifo.on('readable', () => {
  7. const chunk = fifo.read(1024 ** 2);
  8. if (chunk !== null) {
  9. let t1 = Date.now();
  10. process.stdout.write(`${(t1 - t0)/1000.}s, ${1000./(t1 - t0)}fpsn`);
  11. t0 = t1;
  12. }
  13.  
  14. });
  15.  
  16. fifo.on('end', () => {
  17. process.stdout.write('end');
  18. });
  19.  
  20. import sys
  21. import numpy as np
  22.  
  23. im = np.random.randint(0, 255, size=(1024, 1024)).astype(np.uint8).ravel()
  24.  
  25. with open(sys.argv[1], 'wb') as f:
  26. while True:
  27. f.write(im.tobytes())
  28. f.flush()
  29.  
  30. import sys
  31. import numpy as np
  32. import time
  33.  
  34. l = 1024 ** 2
  35. t0 = time.time()
  36. with open(sys.argv[1], 'rb') as f:
  37. while True:
  38. im = f.read(l)
  39. t1 = time.time()
  40. print('{}s, {}fps'.format(t1 - t0, 1/(t1 - t0)))
  41. t0 = t1
  42.  
  43. mkfifo /tmp/video; python producer.py /tmp/video & node reader.js /tmp/video
  44.  
  45. mkfifo /tmp/video; python producer.py /tmp/video & python reader.py /tmp/video
Add Comment
Please, Sign In to add comment