作者:Jamie-逗比 | 来源:互联网 | 2023-07-14 17:24
通过命令行录音
ffmpeg -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支持的设备
ffmpeg -f avfoundation -list_devices true -i ''
[AVFoundation indev @ 0x7f826452d700] AVFoundation video devices:
[AVFoundation indev @ 0x7f826452d700] [0] FaceTime高清摄像头(内建)
[AVFoundation indev @ 0x7f826452d700] [1] Capture screen 0
[AVFoundation indev @ 0x7f826452d700] [2] Capture screen 1
[AVFoundation indev @ 0x7f826452d700] [3] Capture screen 2
[AVFoundation indev @ 0x7f826452d700] AVFoundation audio devices:
[AVFoundation indev @ 0x7f826452d700] [0] Built-in Microphone
指定设备进行录音
# 在Mac上通过编号指定设备
ffmpeg -f avfoundation -i :0 out.wav
# :0表示使用0号音频设备
# 0:0表示使用0号视频设备和0号音频设备
ffplay out.wav
- 可以使用快捷键Ctrl + C终止录音
- 我这边的测试结果显示,默认的音频参数是:
- Mac:48000Hz采样率、16位深度、2声道、1536Kbps比特率
录制视频和音频
ffmpeg -f avfoundation -i 0:0 out.mp4
ffplay out.mp4
查看参数
ffmpeg -devices -hide_banner
Devices:
D. = Demuxing supported
.E = Muxing supported
--
D avfoundation AVFoundation input device
D lavfi Libavfilter virtual input device
E sdl,sdl2 SDL2 output device
D x11grab X11 screen capture, using XCB
- Demuxing supported D代表解复用器
- Muxing supported E表示复用器
ffmpeg -h demuxer=avfoundation -hide_banner
Demuxer avfoundation [AVFoundation input device]:
AVFoundation indev AVOptions:
-list_devices .D........ list available devices (default false)
-video_device_index .D........ select video device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
-audio_device_index .D........ select audio device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
-pixel_format .D........ set pixel format (default yuv420p)
-framerate
ffmpeg -f avfoundation -audio_device_index 0 -i ""
Input #0, avfoundation, from '':
Duration: N/A, start: 42170.757098, bitrate: 2822 kb/s
Stream #0:0: Audio: pcm_f32le, 44100 Hz, stereo, flt, 2822 kb/s
At least one output file must be specified
ffmpeg -f avfoundation -video_device_index 0 -i ""
[avfoundation @ 0x7fafb100a200] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7fafb100a200] Supported pixel formats:
[avfoundation @ 0x7fafb100a200] uyvy422
[avfoundation @ 0x7fafb100a200] yuyv422
[avfoundation @ 0x7fafb100a200] nv12
[avfoundation @ 0x7fafb100a200] 0rgb
[avfoundation @ 0x7fafb100a200] bgr0
[avfoundation @ 0x7fafb100a200] Overriding selected pixel format to use uyvy422 instead.
Input #0, avfoundation, from '':
Duration: N/A, start: 42259.834733, bitrate: N/A
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, 20 tbr, 1000k tbn, 1000k tbc