Thursday, July 30, 2020

Making GIF of iOS Simulator without additional apps

This is how I did it.

First, you need to open Terminal and execute this command:

```
xcrun simctl io booted recordVideo \
--code=h264 \
--force "$( date +%Y%m%d%H%M%S ).mov"

```

Running this will record the Simulator screen until you press `Control+C`. The filename will be something like `20200730095757.mov`. The next step is to convert this video into GIF, FFMPEG is required for this. You can either install it via Homebrew but I prefer running it in a Docker container, something like this:

```
docker run --rm -it -v $PWD:/data -w /data --entrypoint /bin/bash jrottenberg/ffmpeg
```

Once you have FFMPEG installed or are inside the container, execute this command:

```
ffmpeg -i 20200730095757.mov \
-vf "fps=fps=5,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
20200730095757.gif

```

I have played around with the command line arguments and came up with those. Basically it will create a decent GIF to use in issue report etc. Because of the low frame rate, it won't be very smooth but the filesize is acceptable. See these additional links to tweak it further if you want to:


Demo: