FFmpeg | 录制摄像头和桌面数据mac
设备枚举
查看设备列表
$ ffmpeg -hide_banner -devices
Devices:
D. = Demuxing supported
.E = Muxing supported
--
D avfoundation AVFoundation input device
D lavfi Libavfilter virtual input device
E sdl,sdl2 SDL2 output device
可以看到输入设备有:avfoundation,lavfi
输出设备有:sdl
``
设备采集举例:
$ ffmpeg -f avfoundation -list_devices true -i " "
看到了 如下设备
[AVFoundation input device @ 0x7fac75c048c0] AVFoundation video devices:
[AVFoundation input device @ 0x7fac75c048c0] [0] FaceTime高清摄像头(内建)
[AVFoundation input device @ 0x7fac75c048c0] [1] Capture screen 0
[AVFoundation input device @ 0x7fac75c048c0] AVFoundation audio devices:
[AVFoundation input device @ 0x7fac75c048c0] [0] Built-in Microphone
采集摄像头
采集内置摄像头
$ ffmpeg -f avfoundation -i "FaceTime高清摄像头" out.mp4
//或者使用索引号 0 来代替摄像头设备名称
ffmpeg -f avfoundation -i 0 out.mp4
[avfoundation @ 0x7fbf16808200] Selected framerate (29.970030) is not supported by the device.
[avfoundation @ 0x7fbf16808200] Supported modes:
[avfoundation @ 0x7fbf16808200] 640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7fbf16808200] 640x480@[29.000049 29.000049]fps
[avfoundation @ 0x7fbf16808200] 640x480@[28.000067 28.000067]fps
[avfoundation @ 0x7fbf16808200] 640x480@[27.000027 27.000027]fps
[avfoundation @ 0x7fbf16808200] 640x480@[26.000026 26.000026]fps
[avfoundation @ 0x7fbf16808200] 640x480@[25.000000 25.000000]fps
日志告诉我们 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 "FaceTime高清摄像头" out.mp4
把摄像头和麦克风的数据存到一个文件里,使用命令:
ffmpeg -f avfoundation -video_size 640x480 -framerate 30 -video_device_index 0 -i ":0" out.mp4
//或者
ffmpeg -f avfoundation -video_size 640x480 -framerate 30 -i "0:0" out.mp4
播放录制的视频数据
ffplay out.mp4
采集桌面
ffmpeg -f avfoundation -i "Capture screen 0" -r:v 30 screen.mp4
//或者使用索引号1 来代替屏幕设备名称
ffmpeg -f avfoundation -i 1 -r:v 30 screen.mp4
播放采集到的桌面数据
ffplay screen.mp4
参数"Capture screen 0"指定了输入设备,我们也可以将桌面图像带上鼠标一起录制下来,加上参数-capture_cursor
ffmpeg -f avfoundation -capture-cursor 1 -i "Capture screen 0" -r:v 30 screen.mp4
然后播放screen.mp4验证。ffplay screen.mp4
--完--
- 原文作者: 留白
- 原文链接: https://zfunnily.github.io/2020/08/macffmpeg/
- 更新时间:2024-04-16 01:01:05
- 本文声明:转载请标记原文作者及链接