Created
November 11, 2021 01:21
-
-
Save buntagonalprism/1e8172d4eb418a431bf256dfe21a86ca to your computer and use it in GitHub Desktop.
Use Android Debug Bridge (ADB) to record a gif from a connected physical device or emulator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adb devices | |
$screenSize = adb shell wm size | |
$sizeMatches = [regex]::match($screenSize, '(\d+)x(\d+)') | |
$screenHeight = $sizeMatches.Groups[2].Value | |
$screenWidth = $sizeMatches.Groups[1].Value | |
$recordHeight = $screenHeight / 2 | |
$recordWidth = $screenWidth / 2 | |
$recordingSize = "${recordWidth}x${recordHeight}" | |
$recordingName = "recording_" + [DateTimeOffset]::Now.ToUnixTimeSeconds() + ".mp4" | |
$recordingPath = "/sdcard/${recordingName}" | |
Write-Output "Recording at size $recordingSize to file $recordingPath" | |
Write-Output "Press CTRL+C in the spawned window to stop recording..." | |
Start-Process -Wait "adb" -ArgumentList "shell screenrecord --size $recordingSize $recordingPath" | |
adb pull $recordingPath | |
adb shell rm $recordingPath | |
if ($args[0]) { | |
$gifName = $args[0] | |
} | |
else { | |
$gifName = $recordingName -replace ".mp4", ".gif" | |
} | |
ffmpeg -i $recordingName -vf "fps=20,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" $gifName | |
Remove-Item $recordingPath | |
Write-Output "Created $gifName" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment