As you may have heard, we recently released an update to LEADTOOLS mobile technologies. Part of the update included new demos, which we wanted to highlight with some new marketing videos. After some research, I determined that ADB (Android Debug Bridge) and a batch file was going to be the best way to capture videos and screens of the demos on the device. In this setup, I was able to run a command in the console to start the capture and pull the file from the device to my local file system with one command. After almost breaking the USB connector in my phone, I figured out how to do it over Wi-Fi.
At the bottom of this post is the batch file that I came up with.
Simply type record 0
to take a screenshot from the device or
record 30
to record everything that happens on the device's screen for the next 30 seconds.
At the end of the script are steps on how to connect ADB to the device over Wi-Fi, so you can disconnect from USB and not be tethered to your computer. Angels sang when I found that info. 👼
Setting up ADB was pretty simple. I installed Android Studio, which includes ADB. Then I updated my PATH variable to include
"%HOMEPATH%/AppData/Local/Android/android-sdk/platform-tools"
That was it for my computer.
On the phone, I just needed to go to Settings to check "Enable USB Debugging". Easy peasy.
And finally, the batch file that is more comments than batch: RECORD.bat
@echo off
goto :Code
==============================================================================
RECORD.BAT
Usage:
Only the first parameter is used and should be an integer>=0
%1>0 will record video for that many number of seconds (mp4)
%1==0 will take a screenshot (png)
The file name created will be named based on the time the file is pulled
from the device.
==============================================================================
==============================================================================
:Code
adb devices
if %1==0 (
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename "screen.png" %%d-%%e-%%f.png
) else (
adb shell screenrecord --time-limit %1 --bit-rate 6000000 /sdcard/demo.mp4
adb pull /sdcard/demo.mp4
adb shell rm /sdcard/demo.mp4
for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename "demo.mp4" %%d-%%e-%%f.mp4
)
goto :End
=============================================================================
==============================================================================
:: MORE NOTES:
:: I know these empty labels at the beginning of the lines are not needed,
:: but they make syntax highlighting so much nicer in sublime!
:: If you want to disconnect from USB, you can connect ADB via wireless:
:: First, connect to USB as normal:
:: Get the Wi-Fi ip address. There are a couple ways to do this:
:: GET IP ADDRESS:
:: List the nics on the device. You can find the ip address for the wlan there.
adb shell netcfg
:: LISTEN ON A PORT:
:: Have the device listen on port 5555:
adb tcpip 5555
:: Disconnect the device from USB:
:: Connect ADB to the device via the IP address:
adb connect [DEVICE-IP-ADDRESS]
:: Confirm you are connected:
adb devices
:: If the adb connection is ever lost:
:: 1 - Make sure that your host is still connected to the same network as your Android device.
:: 2 - Reconnect by executing the "adb connect" step again.
:: 3 - Or if that doesn't work, reset your adb host:
adb kill-server
:: and then start over from the beginning:
=============================================================================
==============================================================================
:End