https://blog.csdn.net/davidullua/article/details/120562737
https://zhuanlan.zhihu.com/p/568794759?utm_id=0
查看当前系统支持的设备基本信息
ffmpeg -devices
输出:
#解封装或封装的支持情况
Devices:
D. = Demuxing supported
.E = Muxing supported
--
#设备列表
E audiotoolbox AudioToolbox output device
D avfoundation AVFoundation input device
D lavfi Libavfilter virtual input device
查看avfoundation的参数(以avfoundation为例)
ffmpeg -h demuxer=avfoundation
输出:主要涉及枚举设备、音视频设备编号、像素格式、帧率、图像分辨率等参数
Demuxer avfoundation [AVFoundation input device]:
AVFoundation indev AVOptions:
-list_devices <boolean> .D......... list available devices (default false)
-video_device_index <int> .D......... select video device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
-audio_device_index <int> .D......... select audio device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
-pixel_format <pix_fmt> .D......... set pixel format (default yuv420p)
-framerate <video_rate> .D......... set frame rate (default "ntsc")
-video_size <image_size> .D......... set video size
-capture_cursor <boolean> .D......... capture the screen cursor (default false)
-capture_mouse_clicks <boolean> .D......... capture the screen mouse clicks (default false)
-capture_raw_data <boolean> .D......... capture the raw data from device connection (default false)
-drop_late_frames <boolean> .D......... drop frames that are available later than expected (default true)
枚举avfoundation支持的输入设备
ffmpeg -f avfoundation -list_devices true -i ""
输出:可以看到三个视频设备(摄像头,录屏0,录屏1),三个音频设备
[AVFoundation indev @ 0x7fa2fa904500] AVFoundation video devices:
[AVFoundation indev @ 0x7fa2fa904500] [0] FaceTime高清摄像头(内建)
[AVFoundation indev @ 0x7fa2fa904500] [1] Capture screen 0
[AVFoundation indev @ 0x7fa2fa904500] [2] Capture screen 1
[AVFoundation indev @ 0x7fa2fa904500] AVFoundation audio devices:
[AVFoundation indev @ 0x7fa2fa904500] [0] TFFAudio
[AVFoundation indev @ 0x7fa2fa904500] [1] MacBook Pro麦克风
[AVFoundation indev @ 0x7fa2fa904500] [2] WeMeet Audio Device
采集摄像头数据
使用电脑自带摄像头设备录制
ffmpeg -f avfoundation -s 1280x720 -r 30 -t 00:00:10 -i 0 out.mp4
ffmpeg -f avfoundation -s 1280x720 -r 30 -t 00:00:10 -i 0 out.yuv
使用电脑屏幕录制
ffmpeg -f avfoundation -capture_cursor 1 -t 00:00:10 -i 1 -r 30 out.mp4
--视频选项
-f: fmt, force format
-s: size, set frame size (WxH)
-r: rate, set frame rate (Hz)
-fpsmax: set max frame rate (Hz)
-aspect: set aspect ratio (4:3, 16:9, or 1.3333, 1.7777)
-t: duration, 录制或转码时间,单位秒
-i: input, 输入文件路径或者输入设备ID
-vf: 设置视屏过滤器,例如-vf scale=640:640,效果同-s 640x640
-pix_fmt format:设定视频流的图像格式(如RGB还是YUV)。
-vcodec: 强制视频编码格式,force video codec ('copy' to copy stream)
-capture_cursor:是否添加鼠标运动,0或1, 录屏使用
--音频选项
-aframes:等价于frames:a,输出选项,用于指定输出的音频帧数目。
-aq:等价于q:a,老版本为qscale:a,用于设定音频质量。
-atag:等价于tag:a,用于设定音频流的标签。
-af:等价于filter:a,用于设定一个声音的后处理过滤链,其参数为一个描述声音后处理链的字符串。
采集麦克风
单独录制音频,Mac使用“MacBook Pro麦克风”设备
ffmpeg -f avfoundation -i :1 out.wav
同时录制音视频
ffmpeg -f avfoundation -r 30 -s 1280x720 -i 0:1 out.mp4