Android截图命令screencap与视频录制命令screenrecord

Android截图命令screencap

查看帮助命令

bixiaopeng@bixiaopeng ~$ adb shell screencap -v
screencap: invalid option -- v
usage: screencap [-hp] [-d display-id] [FILENAME]
-h: this message
-p: save the file as a png.
-d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.

注意:

如果文件名以.png结尾时,它将保存为png文件

如果文件名没有给出,则结果被会被输出到stdout

截图保存到SD卡里再导出

$ adb shell screencap -p /sdcard/screen.png
$ adb pull /sdcard/screen.png
$ adb shell rm /sdcard/screen.png

这种方法比较麻烦,需要3步:1. 截图保存到sdcard 2.将图片导出 3.删除sdcard中的图片

截图直接保存到电脑

$ adb shell screencap -p | sed 's/\r$//' > screen.png

执行adb shell 将\n转换\r\n, 因此需要用sed删除多余的\r

如果直接当命令用还可以用 alias 包裝装起來:

$ alias and-screencap="adb shell screencap -p | sed 's/\r$//'"
$ and-screencap > screen.png

以后就可以方便的用and-screencap > 直接将截图保存到电脑上了

转:http://blog.csdn.net/wirelessqa/article/details/22725581

Android视频录制命令screenrecord

你要知道:

  • screenrecord是一个shell命令
  • 支持Android4.4(API level 19)以上
  • 支持视频格式: mp4

一些限制

  • 某些设备可能无法直接录制,原因是分辨率太高,如果遇到此类问题,请试着指定较低的分辨率
  • 不支持录制过程中屏幕旋转,如果录制过程中旋转,有可能画面被切断
  • 录制视频的时候声音不会被录下来

开始录制命令:

adb shell screenrecord /sdcard/demo.mp4

说明:录制手机屏幕,视频格式为mp4,存放到手机sd卡里,默认录制时间为180s

限制录制时间:

参数: --time-limit

adb shell screenrecord --time-limit 10 /sdcard/demo.mp4

说明:限制视频录制时间为10s,如果不限制,默认180s

指定视频分辨率大小:

参数: --size

adb shell screenrecord --size 1280*720 /sdcard/demo.mp4

说明:录制视频,分辨率为1280*720,如果不指定默认使用手机的分辨率,为获得最佳效果,请使用设备上的高级视频编码(AVC)支持的大小

指定视频的比特率

参数: --bit-rate

adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4

说明:指定视频的比特率为6Mbps,如果不指定,默认为4Mbps. 你可以增加比特率以提高视频质量或为了让文件更小而降低比特率

在命令行显示log

参数: --verbose

bixiaopeng@bixiaopeng wirelessqa$ adb shell screenrecord --time-limit 10 --verbose /sdcard/demo.mp4
Main display is 1080x1920 @60.00fps (orientation=0)
Configuring recorder for 1080x1920 video at 4.00Mbps
Content area is 1080x1920 at offset x=0 y=0
Time limit reached
Encoder stopping; recorded 96 frames in 10 seconds
Stopping encoder and muxer
Executing: /system/bin/am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/demo.mp4
Broadcasting: Intent { act=android.intent.action.MEDIA_SCANNER_SCAN_FILE dat=file:///sdcard/demo.mp4 }
Broadcast completed: result=0

旋转90度

参数: --rotate

说明:此功能为实验性的,好不好用不知道

查看帮助命令

参数: --help

bixiaopeng@bixiaopeng ~$ adb shell screenrecord --help
Usage: screenrecord [options] <filename>
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 megabits per second. Default 4Mbps.
--time-limit TIME
Set the maximum recording time, in seconds. Default / maximum is 180.
--rotate
Rotate the output 90 degrees.
--verbose
Display interesting information on stdout.
--help
Show this message.
Recording continues until Ctrl-C is hit or the time limit is reached.

导出视频:

adb pull /sdcard/demo.mp4

说明:导出视频到当前目录

www.wirelessqa.me

posted @   程序员修练之路  阅读(2374)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示