不管是教育,仍是为了演示,假如能将Android手机(或平板)的屏幕录制成视频文件,那是一件十分酷的事(iOS8现已供给了这一功用,能经过OSX直接在Mac上录制iPad、iPhone的屏幕,windows没试过,不知可不能够)。不过曾经的办法都是经过截屏录制的,作用极差。幸亏Android4.4以上版别供给了这一功用。但无法在手机上直接发动,需求经过adb运用指令行发动。
我们能够进入shell。或爽性直接用adbshell执行指令。该指令是screenrecord,能够输入screenrecord –help,看看协助,如下所示。
Usage: screenrecord [options]
Android screenrecord v1.2. Records the device’s display to a .mp4 file.
Options:
–size WIDTHxHEIGHT
Set the videosize, e.g. 1280×720. Defaultis the device’s main
displayresolution (if supported), 1280×720 if not. For best results,
use a sizesupported by the AVC encoder.
–bit-rate RATE
Set thevideo bit rate, in bits per second. Value may be specified as
bits ormegabits, e.g. ‘4000000’ is equivalent to ‘4M’. Default 4Mbps.
–bugreport
Addadditional information, such as a timestamp overlay, that is helpful
in videoscaptured to illustrate bugs.
–time-limit TIME
Set themaximum recording time, in seconds. Default / maximum is 180.
–verbose
Displayinteresting information on stdout.
–help
Show thismessage.
Recording continues until Ctrl-C is hit or the timelimit is reached.
从这些协助信息能够了解到,screenrecord需求后边跟一个mp4文件名。最简略的方式如下:
screenrecord /sdcard/game.mp4
但要留意,mp4要写入的目录有必要是可写的。
输入完指令后,直接按回车,指令会被堵塞,默许什么都不会输出,这是正在录制呢。操作手机的一切画面都会被录制下来。假如要输出相应的信息,需求加–verbose指令行参数,加该指令行参数,整个录制进程可能会输出如下相似的信息。
Main display is 1080×1920 @60.00fps (orientation=0)
Configuring recorder for 1080×1920 video/avc at4.00Mbps
Content area is 1080×1920 at offset x=0 y=0
^CEncoder stopping; recorded 68 frames in 12 seconds
Stopping encoder and muxer
Executing: /system/bin/am broadcast -aandroid.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/test.mp4
Broadcasting: Intent {act=android.intent.action.MEDIA_SCANNER_SCAN_FILE dat=file:///sdcard/test.mp4 }
Broadcast completed: result=0
当然,能够跟许多选项,常用的便是–size(尺度)、–bit-rate(比特率)和–time-limit(录制最大时刻)
尺度默许是当时手机屏幕分辨率、比特率是默许4Mbps、录制时刻默许是3分钟(180秒)
screenrecord –time-limit 100 /sdcard/game.mp4
上面的指令最大可录制100秒的视频。假如想半途中止录制,可按Ctrl C,停止录制,game.mp4仍然会生成,但只会录制从开端录制到按Ctrl-C这段时刻的视频。下图是我录制的20秒射击游戏的作用图。完好视频可在下面的地址下载。