Skip to content

Instantly share code, notes, and snippets.

@buntagonalprism
Created November 11, 2021 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buntagonalprism/1e8172d4eb418a431bf256dfe21a86ca to your computer and use it in GitHub Desktop.
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
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