视频录制和图像截取
视频录制和图像截取需要root权限后进入shell模式,使用 adb shell 命令即可进入shell模式.
视频录制: screenrecord
1.使用 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.
2.screenrecord 只能录制.mp4格式的视频,用户可以设置视频文件名称为xxx或者xxx.mp4.
screenrecord /storage/sdcard0/xxx
screenrecord /storage/sdcard0/xxx.mp4
3.使用 --verbose 参数可以查看录制视频的相关信息
screenrecord --verbose /storage/sdcard0/test.mp4
在录制视频的时候按Ctrl + C 停止录制视频,查看控制台的输出信息:
Main display is 1920x1080 @56.83fps (orientation=0)
Configuring recorder for 1920x1080 video at 4.00Mbps
Content area is 1920x1080 at offset x=0 y=0
Encoder stopping; recorded 341 frames in 45 seconds
Stopping encoder and muxer
Executing: /system/bin/am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/sdcard0/test.mp4
Broadcasting: Intent { act=android.intent.action.MEDIA_SCANNER_SCAN_FILE dat=file:///storage/sdcard0/test.mp4 }
Broadcast completed: result=0
在开始录制视频的时候可以看到设备的尺寸信息等,停止录制视频可以看到视频录制时长信息等.
图像截取: screenshot screencap
1.查看 screenshot 和 screencap 命令介绍
usage: screenshot [-s soundfile] filename.png
-s: play a sound effect to signal success
-i: autoincrement to avoid overwriting filename.png
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.
2.screenshot 和 screencap 都是用于截图的命令,那么两个命令之间有什么区别呢?
- 使用screenshot 截屏时不需要添加-p参数,并且保存的文件名称也不一定要以.png结尾,下面两种命令方式都可以实现截屏的效果.
screenshot /storage/sdcard0/1
screenshot /storage/sdcard0/2.png
- screencap 有下面三种截屏方式: 如果没有添加-p参数,文件名必须以.png结尾;如果有-p参数,文件名可以不以.png结尾.
screencap -p /storage/sdcard0/xxx
screencap /storage/sdcard0/xxx.png
screencap -p /storage/sdcard0/xxx.png
以横屏1920x1080分辨率PAD板实际截屏的效果来看,使用 screencap 命令截屏得到的图片分辨率为1920x1080;而使用 screenshot 命令截屏得到的图片分辨率为1080x1920;从截图效果来看推荐使用screencap命令.
导出视频和图片
先退出shell模式(exit),然后可以通过 adb pull 命令将图片或者视频文件导出到本地文件夹.
- 将原文件导出到当前目录
adb pull /storage/sdcard0/xxx .
- 将原文件以yyy为文件名导出到当前目录
adb pull /storage/sdcard0/xxx yyy
- 将原文件以yyy为文件名导出到指定目录
adb pull /storage/sdcard0/xxx /path/yyy