adb-screencap.js 774 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env node
  2. /**
  3. * ADB 截图:根据 IP 截屏并保存到指定路径
  4. * 用法: node adb-screencap.js <ip> <outputPath>
  5. */
  6. const { spawnSync } = require('child_process')
  7. const path = require('path')
  8. const fs = require('fs')
  9. const adb = path.resolve(__dirname, '..', '..', 'lib', 'scrcpy-adb', 'adb.exe')
  10. /** 截图并保存到 outputPath */
  11. function captureScreenshot(ip, outputPath) {
  12. const r = spawnSync(adb, ['-s', ip, 'exec-out', 'screencap', '-p'], { encoding: null, timeout: 10000, maxBuffer: 16 * 1024 * 1024 })
  13. fs.writeFileSync(outputPath, r.stdout)
  14. return { success: true }
  15. }
  16. if (require.main === module) {
  17. captureScreenshot(process.argv[2], process.argv[3])
  18. process.stdout.write(process.argv[3])
  19. }
  20. module.exports = { captureScreenshot }