Android录屏和截屏命令

视频录制和图像截取

视频录制和图像截取需要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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,283评论 25 708
  • iOS 11 适配 1.1. tableview适配 1.2 HUD不显示HUD 必须添加在窗口的keyWindo...
    光彩影阅读 215评论 0 1
  • 脑海里一直幻想这样的情景 我站在大片紫色薰衣草的花田 纵横的小路延伸到木屋门前 远处是城市高楼影像的变幻 木屋左边...
    蜜蜜鸢尾阅读 527评论 7 6
  • 前一篇 《论语解悟》里仁 第八、九、十章 后一篇 《论语解悟》里仁第十四、十五章 [原文] 子曰:君子怀德,小人怀...
    为仁由己zj阅读 1,028评论 2 2
  • 还有拿盗版书来比价格的,真的很无语。书的印刷质量好坏孩子说不出来,但是肯定有感觉,就像是弹钢琴和电子琴,触感不同。
    果果和聚聚阅读 224评论 0 0