您的位置:首页 > 移动开发 > Android开发

Android系统如何录制屏幕(录制成mp4格式)

2014-11-30 20:40 495 查看
不管是教学,还是为了演示,如果能将Android手机(或平板)的屏幕录制成视频文件,那是一件非常酷的事(iOS8已经提供了这一功能,能通过OSX直接在Mac上录制iPad、iPhone的屏幕,windows没试过,不知可不可以)。不过以前的方法都是通过截屏录制的,效果极差。幸好Android4.4以上版本提供了这一功能。但无法在手机上直接启动,需要通过adb使用命令行启动。
大家可以进入shell。或干脆直接用adbshell执行命令。该命令是screenrecord,可以输入screenrecord --help,看看帮助,如下所示。

Usage: screenrecord [options] <filename>
Android screenrecord v1.2. Records the device's display to a .mp4 file.
Options:

--size WIDTHxHEIGHT
Set the videosize, e.g. "1280x720". Defaultis the device's main
displayresolution (if supported), 1280x720 if not. For best results,
use a sizesupported by the ***C 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 1080x1920 @60.00fps (orientation=0)
Configuring recorder for 1080x1920 video/avc at4.00Mbps
Content area is 1080x1920 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秒射击游戏的效果图。完整视频可在下面的地址下载。



录制视频下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: