Androidのスクリーンの動画を撮る
4.4から可能になったadb screenrecord
Android4.4以降からadbをつかってスクリーンの動画をとることができます。どのアプリを起動していてもできるので、他のアプリの演出を録画したり、自分のアプリのプロモーション用の動画の材料を作ったりと、用途は無限大です。しかも60fpsくらい?
$: adb shell screenrecord --time-limit 30 /path/to/save/filename.mp4
このコマンドを実行するだけです。
非エンジニアが実行したい・・・!
という要望がかなりあるはず。ということで、職場の環境上ベストな(共有で使っているMacが1台あったので)AppleScript化で解決してみました。
環境構築
- Android Studioを入れてSDK諸々をインストールする所までぽちぽちしていきます。
- Platformツールがインストールされたパスを調べる(
/Users/USER/Library/Android/adb
らへん)。 - Apple Scriptでキャプチャコマンドを実行する
- AppとしてExportする
ソース
AppleScriptのプロジェクトだとバイナリのようになるのでサンプルソースを置いておきます。
AndroidRecorder.scpt
on main() set command to "/usr/local/bin/adb shell screenrecord --time-limit 30 " set y to ((year of (current date)) as string) set mon to (((month of (current date)) as integer) as string) set d to ((day of (current date)) as string) set h to ((hours of (current date)) as string) set min to ((minutes of (current date)) as string) set s to ((seconds of (current date)) as string) set filepath to ("/sdcard/" & y & mon & d & "_" & h & min & s & ".mp4") set command to (command & filepath) display dialog " \ / / ̄ ̄ ̄\ / ● ● ヽ L______| ∩∧∧∩ |(゚∀゚)| 録画を開始します。 ヽ ノ 録画は30秒間行われます。 ~/ < ( (⌒\\ ※途中でケーブルを抜けば i⌒Y ̄ ̄ ̄ ̄ ̄Y⌒i 録画は終了します。 | | | | | | | | ヽ_| |_ノ \____/ | || | ヽノヽノ 書き込み先: " & filepath with title "Android Recorder" do shell script (command) end main on run my main() end run
実行
OKをクリックすると撮影が開始されます。
まとめ
Appに吐き出して、GUIベースでコマンドや他のアプリをフックできるという点が素晴らしい。 AppleScriptは非エンジニアの為の支援ツールとして作って渡すとちょうどいい。
また、入力GUIも使えるので、--time-limit 30
をフレキシブルにしたりと僅かながら拡張もできそうだ。