发现 Android 系统自带录屏命令 screenrecord,其可执行文件位于:/system/bin/ ,源码位于:frameworks/av/cmds/screenrecord 。
- screenrecord是一个shell命令
- 支持Android4.4(API level 19)以上
- 支持视频格式: mp4
通过 screenrecod --help 帮助命令查看提示选项:
D:\log>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 20Mbps.
--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/screenrecord.mp4
说明:录制手机屏幕,mp4 封装格式,并保存到sdcard,默认录制时间为180s,录制期间可以通过 Ctrl+C 结束录屏。
2. 指定录制时间,参数 --time-limit
adb shell screenrecord --time-limit 20 /sdcard/screenrecord.mp4
说明:--time-limit 设置最大录制时间长度,默认 180 秒,录制期间可以通过 Ctrl+C 结束录屏。
3. 指定视频分辨率大小,参数 --size
adb shell screenrecord --size 1280*720 /sdcard/screenrecord.mp4
说明:录制视频,设定分辨率为1280*720,如果不指定,默认使用手机的分辨率。
4. 指定视频的比特率, 参数 --bit-rate
adb shell screenrecord --bit-rate 6000000 /sdcard/screenrecord.mp4
说明:指定视频的比特率为6Mbps,如果不指定,默认为4Mbps。你可以增加比特率以提高视频质量或为了让文件更小而降低比特率。
5. 旋转90度,参数: --rotate
adb shell screenrecord --rotate /sdcard/screenrecord.mp4
6. 打印Log:
adb shell screenrecord --time-limit 10 --verbose /sdcard/screenrecord.mp4
7. 查看录屏进程pid:
adb shell "ps -A | grep screenrecord"
USER PID PPID VSZ RSS WCHAN ADDR S NAME
root 6430 1 2182300 15068 futex_wait_queue_me 72a5c743b0 S screenrecord
8. 导出视频:
adb pull /sdcard/screenrecord.mp4 D:/
一些限制:
- 某些设备可能无法直接录制,原因是分辨率太高,如果遇到此类问题,请试着指定较低的分辨率
- 不支持录制过程中屏幕旋转,如果录制过程中旋转,有可能画面被切断
- 录制视频的时候声音不会被录下来
推荐阅读:
改进安卓自带screenrecord录屏程序,支持录屏/横竖屏识别/实时推送raw h264.