【ADB命令列】adb shell screenrecord命令列使用說明
阿新 • • 發佈:2019-02-18
一、檢視幫助命令,引數 --help
1 開始錄製命令:
2 指定視訊解析度大小,引數 --size
說明:錄製視訊,解析度為1280*720,如果不指定預設使用手機的解析度,為獲得最佳效果,請使用裝置上的高階視訊編碼(AVC)支援的大小
3 指定視訊的位元率, 引數 --bit-rate
4 旋轉90度,引數: --rotate
5 匯出視訊:
)的除錯模式,使用USB連線手機,DDMS介面Name中出現手機型號及online的狀態
【APP中呼叫shell指令碼】
D:\>adb shell screenrecord --help Usage: screenrecord [options] <filename> Android screenrecord v1.2. Records the device's display to a .mp4 file. Options: --size WIDTHxHEIGHT Set the video size, e.g. "1280x720". Default is the device's main display resolution (if supported), 1280x720 if not. For best results, use a size supported by the AVC encoder. --bit-rate RATE Set the video bit rate, in bits per second. Value may be specified as bits or megabits, e.g. '4000000' is equivalent to '4M'. Default 4Mbps. --bugreport Add additional information, such as a timestamp overlay, that is helpful in videos captured to illustrate bugs. --time-limit TIME Set the maximum recording time, in seconds. Default / maximum is 180. --verbose Display interesting information on stdout. --help Show this message. Recording continues until Ctrl-C is hit or the time limit is reached.
1 開始錄製命令:
adb shell screenrecord /sdcard/demo.mp4
說明:錄製手機螢幕,視訊格式為mp4,存放到手機sd卡里,預設錄製時間為180s。
screenrecord是一個shell命令,支援Android4.4(API level 19)以上,支援視訊格式: mp4
2 指定視訊解析度大小,引數 --size
adb shell screenrecord --size 1280*720 /sdcard/demo.mp4
說明:錄製視訊,解析度為1280*720,如果不指定預設使用手機的解析度,為獲得最佳效果,請使用裝置上的高階視訊編碼(AVC)支援的大小
3 指定視訊的位元率, 引數 --bit-rate
說明:指定視訊的位元率為6Mbps,如果不指定,預設為4Mbps. 你可以增加位元率以提高視訊質量或為了讓檔案更小而降低位元率adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4
4 旋轉90度,引數: --rotate
adb shell screenrecord --rotate /sdcard/demo.mp4
說明:此功能為實驗性的,在nexus6裝置上實驗,錄製的視訊播放時也是旋轉90度播放,體驗不太友好。5 匯出視訊:
adb pull /sdcard/demo.mp4 D:/
說明:匯出視訊的位置在D盤根目錄下,名稱為demo.mp4二、DDMS中使用錄製功能
1.命令列中使用DDMS,開啟Android DDMS(monitor.bat)工具
2.開啟android手機(Android4.4及以上機型
3.Device-->Screen Record,彈出設定頁面,設定視訊的位元率,和視訊的解析度以及儲存路徑,點選OK
4.操作手機測試場景,完畢後,點選Cannel按鈕,等待幾秒後,會彈出提示儲存成功。
【APP中呼叫shell指令碼】
關鍵程式碼:
public static void doCmds(List cmds) throws Exception {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
}
eg.在button的click事件呼叫:
this.btn=(Button) super.findViewById(R.id.btn);
this.btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
List cmds=new ArrayList();
cmds.add("reboot");
try {
MainActivity.doCmds(cmds);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
點選按鈕後,系統會重啟哦。
--------------------------
前提:手機root完,允許root許可權。