现在的位置: 首页 > 综合 > 正文

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

2016年10月17日 ⁄ 综合 ⁄ 共 1929字 ⁄ 字号 评论关闭

 不管是教学,还是为了演示,如果能将Android手机(或平板)的屏幕录制成视频文件,那是一件非常酷的事(iOS8已经提供了这一功能,能通过OS X直接在Mac上录制iPad、iPhone的屏幕,windows没试过,不知可不可以)。不过以前的方法都是通过截屏录制的,效果极差。幸好Android4.4以上版本提供了这一功能。但无法在手机上直接启动,需要通过adb使用命令行启动。

 

      大家可以进入shell。或干脆直接用adb shell执行命令。该命令是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 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.

     从这些帮助信息可以了解到,screenrecord需要后面跟一个mp4文件名。最简单的形式如下:

screenrecord /sdcard/game.mp4    

但要注意,mp4要写入的目录必须是可写的。

     输入完命令后,直接按回车,命令会被阻塞,默认什么都不会输出,这是正在录制呢。操作手机的所有画面都会被录制下来。如果要输出相应的信息,需要加--verbose命令行参数,加该命令行参数,整个录制过程可能会输出如下类似的信息。

Main display is 1080x1920 @60.00fps (orientation=0)

Configuring recorder for 1080x1920 video/avc at 4.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 -a android.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秒射击游戏的效果图。完整视频可在下面的地址下载。

抱歉!评论已关闭.