https://trac.ffmpeg.org/wiki/Capture/Desktop
官网教程
mac安装ffmpeg后,用命令行可以录屏。
1 获取mac的视频设备和音频设备
ffmpeg -f avfoundation -list_devices true -i ""
可以看到,视频设备有摄像头和显示器0/1,音频设备有麦克风
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple clang version 13.1.6 (clang-1316.0.21.2.3)
configuration: --prefix=/usr/local/ffmpeg --enable-debug=3 --enable-shared
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
[AVFoundation input device @ 0x139615350] AVFoundation video devices:
[AVFoundation input device @ 0x139615350] [0] FaceTime HD Camera
[AVFoundation input device @ 0x139615350] [1] Capture screen 0
[AVFoundation input device @ 0x139615350] [2] Capture screen 1
[AVFoundation input device @ 0x139615350] AVFoundation audio devices:
[AVFoundation input device @ 0x139615350] [0] MacBook Pro麦克风
: Input/output error
2 开始录制
第一次录制前需要授权
ffmpeg -f avfoundation -i "0:0" output.mkv
格式不对还会报错,提示分辨率和帧率参数不对
[avfoundation @ 0x159808800] Selected framerate (29.970030) is not supported by the device
[avfoundation @ 0x159808800] Supported modes:
[avfoundation @ 0x159808800] 1280x720@[1.000000 30.000000]fps
[avfoundation @ 0x159808800] 640x480@[1.000000 30.000000]fps
0:0: Input/output error
如下设置之后就可以录制了,按ctrl+c可以停止录制
ffmpeg -video_size 1280x720 -framerate 30 -f avfoundation -i "0:0" output.mkv
输出视频文件是output.mkv
,可以直接播放了。
3 ffplay播放
安装ffplay后,可以实时直接播放摄像头和话筒,把上面命令里的ffmpeg换成ffplay,去掉output.mkv输出文件就行了!
ffplay -video_size 1280x720 -framerate 30 -f avfoundation -i "0:0"