├── LICENSE ├── README.md └── xcrecord /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Klaas Pieter Annema 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xcrecord 2 | 3 | Capture GIFs from the iOS simulator 🎥 4 | 5 | # Install 6 | 7 | ```sh 8 | brew tap klaaspieter/homebrew-formula 9 | brew install xcrecord 10 | ``` 11 | 12 | Note that xcrecord currently does not work with ffmpeg 4.0 ([#2]). Downgrade to 3.4.2 instead: 13 | 14 | ```sh 15 | brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/18b47ee7e250f4e0447dc6454d9189d1fae0c6a5/Formula/ffmpeg.rb 16 | brew switch 3.4.2 17 | ``` 18 | 19 | [#2]: https://github.com/klaaspieter/xcrecord/issues/2 20 | 21 | # Usage 22 | 23 | ```sh 24 | xcrecord [OPTION] file 25 | 26 | OPTIONS 27 | 28 | -v --version 29 | Prints the version number 30 | 31 | -s --scale --no-scale 32 | Scale (resize) the GIF using ffmpeg. Accepts the same options ffmpeg does. The default is “-1:480”. 33 | See https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg for more information. 34 | 35 | ``` 36 | -------------------------------------------------------------------------------- /xcrecord: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | name=$(basename "$0") 4 | 5 | show_usage() { 6 | echo "Usage: $name [--version][--scale] " 7 | exit 1 8 | } 9 | 10 | show_version() { 11 | echo "$name version 1.0.2" 12 | } 13 | 14 | xcrecord() { 15 | xcrun_destination=$(mktemp) 16 | xcrun simctl io booted recordVideo "$xcrun_destination" 17 | 18 | palette=$(mktemp "$TMPDIR$(uuidgen).png") 19 | paletteops="stats_mode=diff" 20 | filters=fps=10 21 | 22 | if [ -z "$scale" ]; then 23 | scale="-1:480" 24 | fi 25 | 26 | if [ -z "$no_scale" ]; then 27 | filters=$filters,scale="$scale":flags=lanczos 28 | fi 29 | 30 | ffmpeg_destination="$(mktemp "$TMPDIR""$(uuidgen)".gif)" 31 | 32 | ffmpeg -loglevel quiet \ 33 | -i "$xcrun_destination" \ 34 | -vf "$filters,palettegen=$paletteops" \ 35 | -y "$palette" 36 | ffmpeg -loglevel quiet \ 37 | -i "$xcrun_destination" \ 38 | -i "$palette" \ 39 | -filter_complex "$filters [x]; [x][1:v] paletteuse" \ 40 | -y "$ffmpeg_destination" 41 | 42 | gifsicle --optimize=3 --output "$output" "$ffmpeg_destination" 43 | 44 | rm -r "$xcrun_destination" "$palette" "$ffmpeg_destination" 45 | } 46 | 47 | platform=$(uname | cut -d _ -f 1 | tr '[:upper:]' '[:lower:]') 48 | 49 | case "$platform" in 50 | "darwin") 51 | GETOPT="$(brew --prefix gnu-getopt 2>/dev/null || echo /usr/local)/bin/getopt" 52 | ;; 53 | *) 54 | GETOPT="getopt" 55 | ;; 56 | esac 57 | 58 | if ! ARGS=$($GETOPT --long version,scale:,no-scale --options vs: -- "$@") 59 | then 60 | show_usage 61 | fi 62 | 63 | eval set -- "$ARGS" 64 | while [ $# -gt 0 ] 65 | do 66 | case "$1" in 67 | -v|--version) 68 | show_version 69 | exit 70 | ;; 71 | -s|--scale) 72 | scale=$2 73 | shift 2 74 | ;; 75 | --no-scale) 76 | no_scale=true 77 | shift 78 | ;; 79 | --) 80 | shift 81 | break 82 | ;; 83 | esac 84 | done 85 | 86 | shift "$((OPTIND - 1))" 87 | 88 | while true ; do 89 | case $1 in 90 | ?*) 91 | output=$1 92 | shift 93 | break 94 | ;; 95 | *) 96 | show_usage 97 | ;; 98 | esac 99 | done 100 | 101 | xcrecord 102 | --------------------------------------------------------------------------------