版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1341964
在平时写博客的时候,我们经常需要截图,录制视屏,或者制作 gif 动图。今天,我们就依赖来讨论一下有哪些方法。
手机屏幕投影到电脑,在利用电脑上的软件进行截图,录制视频,或者制作 gif 动图。
手机屏幕同步都电脑,我们可以使用 Vysor 这个 chrome 插件,截图我们可以 使用 QQ 截图快捷键 Ctrl + Alt + A, 制作 gif 动图我们可以使用 gif 转换工具 LICEcap
下载地址
使用 adb 命令。下面让我们一起来看一下怎样使用 adb 命令进行截图。
//(保存到SDCard)
adb shell /system/bin/screencap -p /sdcard/screenshot.png
// 从SD卡导出到电脑,注意 F:\\mvp 为电脑路径,必须存在
adb pull /sdcard/screenshot.png F:\\mvp(保存到电脑)
如果你想删除手机上的图片,那么你可以使用这个命令来删除
adb shell rm /sdcard/screen.png
adb shell screencap -p | sed 's/\r$//' > screen.png
需要注意的是,图片会保存在当前 cmd 启动的路径,screen.png 为图片的名字
比如我在 C:\Users\Administrator 执行命令,那么将会保存在 C:\Users\Administrator 目录下。
C:\Users\Administrator>adb shell screencap -p | sed ‘s/\r$//’ > screen.png
如果你觉得每一次都要输入这么长的命令 adb shell screencap -p | sed ‘s/\r$//’ > screen.png ,怕记不住,我们是可以采取一些方法的。那就是用 alias 包装起来,相当于是起别名的意思。
由于 alias 是 linux 特有的命令,我们无法再 windows 使用,如果想在 windows 使用类似的功能,可以参考下面的博客。
在Windows中利用doskey配置类似Linux中alias命令
一些限制
某些设备可能无法直接录制,原因是分辨率太高,如果遇到此类问题,请试着指定较低的分辨率 不支持录制过程中屏幕旋转,如果录制过程中旋转,有可能画面被切断 录制视频的时候声音不会被录下来
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)支持的大小
指定视频的比特率
adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4
说明:指定视频的比特率为6Mbps,如果不指定,默认为4Mbps. 你可以增加比特率以提高视频质量或为了让文件更小而降低比特率
参数: –verbose
adb shell screenrecord --time-limit 10 --verbose /sdcard/demo.mp4
输入以上命令,将可以看到这些信息。
Main display is 1080x1920 @59.16fps (orientation=0)
The max width/height supported by codec is 1920x1088
Configuring recorder for 1088x1920 video/avc at 4.00Mbps
Content area is 1080x1920 at offset x=4 y=0
Time limit reached
Encoder stopping; recorded 133 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
参数: –rotate
说明:此功能为实验性的,好不好用不知道
参数: –help
输入以下命令
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.
adb pull /sdcard/demo.mp4 说明:导出视频到当前目录
到处到指定的目录
adb pull /sdcard/demo.mp4 F:\mvp\demo.mp4
利用 LICEcap 进行转换。
第一种方法,相对于第二种方法( 使用 adb 命令)来说,在截图和录制视频的时候,效率差不多,而在制作 gif 动图的时候,效率会快得挺多的,那为什么还要讲解 adb 命令呢?
一:让大家知道有更多的方法,开阔视野(哈哈,其实我是在扯蛋);
二:使用 Vysor 投影的时候,有一部分手机不支持,作为不是富二代的我们有时很无奈,不可能说为了能使用 Vysor 进行投影,而去重新买一部手机,这时候就退而求其次,使用 adb 命令了。
三: 作为一名开发人员,我们还是要学一些常用的命令的。这样也可以装装逼。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有