Renato Ivancic - Software Engineer

Background image

Gif screen recording

Android Development

Lets say you want to quickly make a short demo of Android application that can be easy embedded into web pages like git, confluence and any other content supporting gif animations. It is dead simple and faster compared with setting up video content. Take a note that the compression shouldn’t be your goal here because mp4 uses better algorithms to decrease the amount of information needed to display a sequence of images. Gif can be a bit smaller at lower resolutions but is also looks much more crappier than mp4.

If you still insists follow these steps:

Record video of device screen

The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file.

To begin recording your device screen, run the screenrecord command to record the video. Then, run the pull command to download the video from the device to the host computer. Here’s an example recording session: Stop the screen recording by pressing Ctrl-C.

$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Ctrl-C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4

Make gif image

Extract images from video

Create directory into which the images should be extracted. In example directory with name “demo” is used.

ffmpeg -i demo.mp4  -r 5 'demo/demo-%03d.jpg'
-r 5 stands for FPS value
    for better quality choose bigger number
    adjust the value with the -delay in 2nd step
    to keep the same animation speed

%03d gives sequential filename number in decimal form

Convert images to gif

cd demo
convert -delay 20 -loop 0 *.jpg demo.gif
-delay 20 means the time between each frame is 0.2 seconds
   which match 5 fps above.
   When choosing this value
       1 = 100 fps
       2 = 50 fps
       4 = 25 fps
       5 = 20 fps
       20 = 5 fps
       100 = 1 fps
       in general 100/delay = fps

-loop 0 means repeat forever

Optional resize gif to decrease the filesize

convert demo.gif -resize 200x200 demo_200.gif
-resize 200x200 means that gif image will be resized so that longest dimension will be 200 pixels long.
   By default the ratio is preserved.

Result:

Gif screen record

Dependencies

Make adb available in terminal

location of adb is in {Android_SDK_Path}/platform-tools/.

If not already be sure to add it to the PATH environmental variable. For linux you have to add below line to ~/.bashrc:

#AndroidDev PATH
export PATH=${PATH}:{Android_SDK_Path}/platform-tools

Update bashrc with following command so you don’t need to restart the system for changes to take effect.

. ~/.bashrc

Install ffmpeg

Linux:

sudo apt install ffmpeg

Mac:

brew install ffmpeg

Sources

Reload bashrc
Android sdk shell
Video to gif
Resize gif

#android