Android 下如何录制App操作生成Gif动态图

jopen 8年前

需求

统计结果1

Android App开发完了,自然希望录个gif做个展示。视频也可以做展示,但是需要上传到优酷、土豆等等,而且本来就十几秒的App演示操作过程,视频网站的广告就要一分钟(吐槽一些),没有gif轻量简单省流量。

上图是我录制的一个短信轰炸机应用,可以查看这篇文章《Android 短信轰炸机App 开发记录》 http://blog.csdn.net/never_cxb/article/details/47614247

本文教大家如何录制gif,本文链接 http://blog.csdn.net/never_cxb/article/details/50515216,转载请注明出处。

思路

生成gif的思路是两步

  1. 把App操作过程录制成视频
  2. 根据视频转换成Gif

目前网上录制GIf的思路也基本都是分为这2步,不知道有没有更好的方法,一步就生成gif动态的?欢迎留言补充

利用adb 录制屏幕

在Android sdk下面有一些很有用的工具,adb位于platform-tools文件夹,开发者用它在设备上安装启动应用。早期的sdk版本中,adb位于tools文件夹中。

在终端(linux或者mac os)或者命令提示符(windows)键入

adb help all

可以列出所有可用的命令。

注意,如果经常使用adb工具,建立把sdk的文件夹路径添加到PATH环境变量中。不加入到环境变量中,每次启动adb都需要cd到platform-tools文件夹的位置。

我们录制屏幕利用 adb shell screenrecord命令,还可以使用adb shell screenshot进行截屏。下面是使用说明

tomchen$ ./adb shell 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.    Recording continues until Ctrl-C is hit or the time limit is reached.    tomchen$ pwd  /Applications/sdk/platform-tools

可以用--size指定视频分辨率的大小,--bit-rate指定比特率的大小。一般我们不需要设置,用默认的就行了。

tomchen$ ./adb shell screenrecord /sdcard/example.mp4

然后就可以录制的,默认时间是180s ,一般不需要这么长,录制完之后我们ctrl+c提前结束就行。
下面利用 pull 命令把手机上的视频拷到电脑上(也可以用手机助手啥的)

adb push <local> <remote> 将电脑上的文件复制到手机(通常是 sd 卡)  adb pull <remote> <local> 将手机上的文件复制到电脑

示例:

tomchen$ ./adb pull /sdcard/example.mp4 ~/Documents/  8786 KB/s (9449246 bytes in 1.050s)

Android studio 自带录制功能

现在一般都不要 Eclipse 开发 Android,转移到 Android Studio,录制屏幕的功能 google 自然想到了,点击开始按钮就行了(适合不熟悉命令行的同学们)
在 Android Studio 最下方的Android栏左边有一个按钮(下图红框圈出的部分),点击就可以实现录屏。还可以选择比特率、分辨率等,分辨率没空则采用默认值。

android

点击Start Recording就开始录制了,会弹出录制时间框

android

录完之后点击Stop Recording,停止录制。

android

最后会提示录制视频的保存位置,自己选个文件夹保存。

Android Studio 也提供了截屏功能,就在录制按钮的上方

android

点击截屏会弹出手机当前的操作界面,还可以用Reload刷新手机界面。

android

视频转 gif

这儿方法也有很多

  • 格式工厂之类的,输入视频格式,导出为gif格式
  • 截取很多帧图片,将多张图片拼接为gif
  • QQ影音工具箱自带了截取一段视频保存为gif格式

本文采用一种最简单的方法,利用一款叫 GifCam 的绿色版软件

Windows 版本的GifCam 可以到这儿下载,不需要下载分数。 http://download.csdn.net/detail/never_cxb/9404806

使用方法很简单,
1. 用一个播放器打开咱们刚才录制好的mp4视频,然后拖动调整 GifCam 大小,让它的透明区域(录制gif区域)覆盖你要录制范围。
2. 点击播放器播放视频,再点击GifCam的Rec按钮,就可以录制gif了。
3. 录完点击stop按钮,选择gif文件保存位置。

android


==============================

本文讲解Android 下如何录制App操作生成Gif动态图,本文链接 http://blog.csdn.net/never_cxb/article/details/50515216,转载请注明出处。

来自: http://blog.csdn.net/never_cxb/article/details/50515216