Android tips(九)-->Android錄屏與轉化gif圖
最近有同學問我android手機的錄屏以及轉化成gif圖是如何實現的?今天正好就講講android的錄屏與轉化gif操作。整個Android系統的錄製與轉化GIF圖是分為兩個部分,錄製過程與轉化過程,下面就詳細的介紹一下這兩個部分的具體過程。
android手機的錄屏操作
android手機也有一些錄製螢幕的軟體,但是作為程式設計師還是推薦使用adb 命令實現對螢幕操作的錄製操作的,而下面我們就介紹一下實現螢幕錄製功能的adb命令:screenrecord。
- 關於screenrecord命令
這裡需要說明的是screenrecord是android 19以後才提供的adb命令,所以你的手機若是android4.4以下就沒辦法使用這個命令執行錄屏操作了…
- screenrecord命令詳解
下面我們在Android Studio的Terminal中執行adb shell screenrecord –help命令看一下關於screenrecord命令的介紹:
➜ platform-tools ./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.
第一行主要說的是screenrecord命令目前版本是1.2,主要用於將裝置的行為錄製成一個.mp4檔案。
最簡單的使用方式是:
screenrecord options xxx.mp4
其中options其可選引數,主要包含:size,bit-rate,bugreport,time-limit,verbose,help等,具體的options的含義上面已經列出來了。
- screenrecord命令實踐
好吧,我們就開始實踐一下通過screenrecord命令錄製螢幕視訊。開啟我們的Android Studio的Terminal,連線手機,然後執行:
./adb shell screenrecord /sdcard/test1.mp4
這裡需要注意的是該命令支援的錄製螢幕最大尺寸為1920 * 1088,更大螢幕的錄製可以使用options size執行螢幕的大小。
然後我們將錄製的視屏名稱為test1.mp4,screenrecord命令預設支援的視訊匯出格式是MP4,所以這裡的名稱就是test1.mp4,但是如果你非要命名為test1,又或者是test1.sss,又或者是test1.txt等等,似乎也沒什麼大礙。
然後我們在手機的sd卡根目錄就出現了一個名稱為test1.mp4的視訊檔案。
視訊轉化gif操作
通過上面的creenrecord錄製命令,我們得到了螢幕操作視訊檔案:test1.mp4,而我們下一步的操作就是將MP4檔案轉化為GIF檔案。由於使用的是mac電腦,嘗試了幾個視訊轉化gif的軟體感覺都不太好,最後發現了一個比較不錯的視訊轉gif的網站:ezgif,可以看一下其主要功能:
主要是一些對GIF圖的操作功能。下面我們就具體看一下如何該網站是如何將MP4檔案轉化為GIF圖的。
將視訊檔案轉化為gif的具體操作
開啟ezgif的Video to GIF功能頁面
- 選擇視訊檔案,執行Upload操作
- 執行具體的Convert to GIF操作
在執行過程中可以設定GIF圖的時長,大小等等引數。
好了,以上就是我們實現Android螢幕錄製與轉化GIF圖的全部操作了,怎麼樣?不是很複雜吧。