0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

xcodeシミュレータ動画撮影〜githubにgifを載せる方法

Last updated at Posted at 2021-04-11

はじめに

xcodeのシミュレータで動画を撮影し,githubの自分のリポジトリのREADMEにgif画像を埋め込むまでの流れを簡単にメモしました.

手順

1. xcodeのシミュレータ動画撮影

方法1

シミュレータ起動時に command + r を入力して録画。Desktopに保存される。

方法2

.movファイルを保存したいディレクトリに移動し,以下のコマンドをterminalで実行.
control + c キーで録画停止.

xcrun simctl io booted recordVideo sample.mov

実行後,次のようなエラーがでた場合,

xcrun: error: unable to find utility "simctl", not a developer tool or in PATH

以下の方法で対処可能.

2. .mov から .gifに変換

ffmpegを利用して.movから.gifに変換する.installしていない場合,homebrewでインストール.

brew install ffmpeg

インストール後,
sample.movが存在するディレクトリで,以下のコマンドを実行すると,同ディレクトリ内にsample.gifが生成される.

ffmpeg -i sample.mov -vf scale=320:-1 -r 10 sample.gif

3. gif画像をGithubのwikiにpush

gif画像を埋め込みたいREADMEが存在するリポジトリの"Wiki"で.gif画像用のリポジトリを別に作成する.
urlは赤丸部分.

image.png

urlよりcloneして,cloneしたディレクトリでgif画像を格納するimagesディレクトリを作成する.
階層は以下の感じ.

.
├── Home.md
└── images
    └── sample.gif

gif画像をimagesディレクトリに格納後,リポジトリの変更内容をpushする.

push後,以下のurlよりアクセス可能.
https://raw.githubusercontent.com/wiki/<ユーザ名>/<リポジトリ名>/images/sample.gif

4. READMEにgif画像を埋め込み

以下のように,記述すると埋め込まれる.なお,"demo"の部分は任意の名前で良い.

![demo](https://raw.githubusercontent.com/wiki/<ユーザ名>/<リポジトリ名>/images/sample.gif)

ffmpegでgifの解像度・容量をコントロール

解像度を犠牲にして軽量なgifを作成

画像がかなり荒い。

ffmpeg -i input.mov -r 10 -vf scale=640:-1 -f gif output.gif

綺麗なgifの作成(1より少し容量大きい)

個人的には、この方法が一番おすすめ。

ffmpeg -i input.mov -filter_complex "[0:v] fps=10,scale=640:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse=dither=none" output-palette-none.gif

補足

動画の再生速度を上げる

以下は4倍速にする例。

ffmpeg -i input.mov -filter:v setpts=PTS/4.0 output.mov

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?