ffmpeg チートシート（macOS版）

Linux版はこちら -> https://qiita.com/miminashi/items/0d82dd1e8da9e635eb12

# 利用可能なフォーマット一覧を表示する

```
ffmpeg -formats
```

# デバイス一覧を表示する

```sh
ffmpeg -f avfoundation -list_devices true -i ""
```

# MacBookProの内蔵カメラを使う

`avfoundation`を入力デバイスとして指定する。
http://ffmpeg.org/ffmpeg-devices.html#avfoundation

# カメラがサポートしているvideo_sizeとframerateの一覧を見る

`-f`と`-i`以外なにも指定しないと

```sh
ffmpeg -f avfoundation -i "0:"
```

https://www.aliexpress.com/item/4000631570932.html の場合だと、

```
[avfoundation @ 0x7f9a93012a00] Supported modes:
[avfoundation @ 0x7f9a93012a00]   320x240@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   1280x720@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   1280x720@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   1280x720@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   1280x720@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   1280x720@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   1280x720@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   1920x1080@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   1920x1080@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   1920x1080@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   1920x1080@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   1920x1080@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   1920x1080@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   2048x1536@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   2048x1536@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   2048x1536@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   2048x1536@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   2048x1536@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   2048x1536@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   320x240@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   352x288@[5.000000 5.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[25.000000 25.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[20.000000 20.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[15.000015 15.000015]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[10.000000 10.000000]fps
[avfoundation @ 0x7f9a93012a00]   640x480@[5.000000 5.000000]fps
```

# MacBook Pro の内蔵マイクで録音する

```sh
ffmpeg -f avfoundation -i ":0" output.wav
```

`":0"`の部分は`":1"`とか`":2"`だったりするかもしれない。

録音したファイルを再生するには、

```sh
ffplay -autoexit output.wav
```

# UVCカメラからファイルに録画する

```shell-session
$ ffmpeg -f avfoundation -video_size 1280x720 -framerate 30 -i "0:" -c:v libx264 -f mp4 camera_0.mp4
```

# カメラの映像をUDPストリームで送る

- 受信側はVLC Playerとかを使う

```shell-session
ffmpeg -f avfoundation -framerate 30 -i "0:" -c:v libx264 -f mpegts udp://127.0.0.1:5000/

# 5MbpsくらいのLTE Cat1回線に通す想定
ffmpeg -f avfoundation -framerate 30 -i "0:" -c:v libx264 -pix_fmt yuv420p -profile baseline -level 1 -tune zerolatency -r 4 -g 48 -x264opts bitrate=3000 -f mpegts udp://127.0.0.1:5000/
```