通过上一篇文章,知道mac 上的摄像头(FaceTime)索引号为0
![](https://i-blog.csdnimg.cn/blog_migrate/d18091701d164588c48a3274012a5145.png)
录制摄像头的,由录制桌面的命令,我们推测录制摄像头的命令应该就是把
-i
的值改为 0即可,下面在shell中跑一下试试:
![](https://i-blog.csdnimg.cn/blog_migrate/0f07fbab203022f98e496d0b09deb198.png)
➜ ~ ffmpeg -f avfoundation -i 0 -r 30 out.yuv
ffmpeg version N-92560-gba71ebbbfa Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.10.44.4)
configuration: --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags=
libavutil 56. 24.101 / 56. 24.101
libavcodec 58. 40.100 / 58. 40.100
libavformat 58. 23.101 / 58. 23.101
libavdevice 58. 6.100 / 58. 6.100
libavfilter 7. 46.101 / 7. 46.101
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
[avfoundation @ 0x7f9ea4800000] Selected framerate (29.970030) is not supported by the device
[avfoundation @ 0x7f9ea4800000] Supported modes:
[avfoundation @ 0x7f9ea4800000] 640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[29.000049 29.000049]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[28.000067 28.000067]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[27.000027 27.000027]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[26.000026 26.000026]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[25.000000 25.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[24.000038 24.000038]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[23.000032 23.000032]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[22.000022 22.000022]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[21.000021 21.000021]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[20.000000 20.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[19.000029 19.000029]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[18.000018 18.000018]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[17.000009 17.000009]fps [avfoundation @ 0x7f9ea4800000] 640x480@[16.000000 16.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[15.000015 15.000015]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[14.000014 14.000014]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[13.000013 13.000013]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[12.000005 12.000005]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[11.000011 11.000011]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[10.000000 10.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[9.000001 9.000001]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[8.000000 8.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[7.000002 7.000002]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[6.000002 6.000002]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[5.000000 5.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[4.000000 4.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[3.000000 3.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[2.000000 2.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[1.000000 1.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[30.000030 30.000030]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[29.000049 29.000049]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[28.000067 28.000067]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[27.000027 27.000027]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[26.000026 26.000026]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[25.000000 25.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[24.000038 24.000038]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[23.000032 23.000032]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[22.000022 22.000022]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[21.000021 21.000021]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[20.000000 20.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[19.000029 19.000029]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[18.000018 18.000018]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[17.000009 17.000009]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[16.000000 16.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[15.000015 15.000015]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[14.000014 14.000014]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[13.000013 13.000013]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[12.000005 12.000005]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[11.000011 11.000011]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[10.000000 10.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[9.000001 9.000001]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[8.000000 8.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[7.000002 7.000002]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[6.000002 6.000002]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[5.000000 5.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[4.000000 4.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[3.000000 3.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[2.000000 2.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[1.000000 1.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[29.000049 29.000049]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[28.000067 28.000067]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[27.000027 27.000027]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[26.000026 26.000026]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[25.000000 25.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[24.000038 24.000038]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[23.000032 23.000032]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[22.000022 22.000022]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[21.000021 21.000021]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[20.000000 20.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[19.000029 19.000029]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[18.000018 18.000018]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[17.000009 17.000009]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[16.000000 16.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[15.000015 15.000015]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[14.000014 14.000014]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[13.000013 13.000013]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[12.000005 12.000005]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[11.000011 11.000011]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[10.000000 10.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[9.000001 9.000001]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[8.000000 8.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[7.000002 7.000002]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[6.000002 6.000002]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[5.000000 5.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[4.000000 4.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[3.000000 3.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[2.000000 2.000000]fps
[avfoundation @ 0x7f9ea4800000] 640x480@[1.000000 1.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[30.000030 30.000030]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[29.000049 29.000049]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[28.000067 28.000067]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[27.000027 27.000027]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[26.000026 26.000026]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[25.000000 25.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[24.000038 24.000038]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[23.000032 23.000032]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[22.000022 22.000022]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[21.000021 21.000021]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[20.000000 20.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[19.000029 19.000029]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[18.000018 18.000018]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[17.000009 17.000009]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[16.000000 16.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[15.000015 15.000015]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[14.000014 14.000014]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[13.000013 13.000013]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[12.000005 12.000005]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[11.000011 11.000011]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[10.000000 10.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[9.000001 9.000001]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[8.000000 8.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[7.000002 7.000002]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[6.000002 6.000002]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[5.000000 5.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[4.000000 4.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[3.000000 3.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[2.000000 2.000000]fps
[avfoundation @ 0x7f9ea4800000] 1280x720@[1.000000 1.000000]fps
0: Input/output error
日志告诉我们 Selected framerate (29.970030) is not supported by the device ,默认的framerate 不被设备支持,下面也给出了支持的分辨率和framerate
所以我们要改一下命令,选取第一个吧 640x480@[30.000030 30.000030]fps
ffmpeg -f avfoundation -video_size 640x480 -framerate 30 -i 0: -r 30 out.yuv
![](https://i-blog.csdnimg.cn/blog_migrate/b4a009ed3f066e0695d633811c96b3c2.png)
覆盖之前的数据,说明已经在录制摄像头了,用ffplay播放一下
ffplay -video_size 640x480 -pix_fmt uyvy422 out.yuv
![](https://i-blog.csdnimg.cn/blog_migrate/02e177046870552a0cc19e1930ad3f9f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4846e3e3f58b452e3403a5eeeeea74b1.png)