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