Android系統如何錄製螢幕(錄製成mp4格式)
不管是教學,還是為了示範,如果能將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秒射擊遊戲的。完整視頻可在下面的地址下載。