本文是上面文章的摘要,只用于自己快速浏览.
目录
命令简介
ffmpeg
ffmpeg的主要作用:对音视频进行编解码。
ffmpeg arg1 arg2 -i arg3 arg4 arg5
arg1:全局参数
arg2:输入文件参数
arg3:输入文件
arg4:输出文件参数
arg5:输出文件
ffprobe
ffprobe的主要作用:查看音视频的参数信息。
ffprobe [OPTIONS] [INPUT_FILE]
OPTIONS:参数
INPUT_FILE:输入文件
ffplay
ffplay的主要作用:播放音视频。
ffplay [options] input_file
options:参数
input_file:输入文件
hide_bannder
增加-hide_bannder参数可以隐藏一些冗余的描述信息,可以去实践比较以下2条命令的区别:
ffprobe xx.mp3
ffprobe -hide_banner xx.mp3
ffmpeg、ffprobe、ffplay都适用
通过命令行录音
使用命令行查看当前平台的可用设备:
ffmpeg -devices
windows有个dshow,是Windows平台的多媒体系统库,我们可以使用dshow去操作多媒体输入设备(比如录音设备)
Mac有个avfoundation,是Mac平台的多媒体系统库,我们可以使用avfoundation去操作多媒体输入设备(比如录音设备)
查看dshow支持的设备
ffmpeg -f dshow -list_devices true -i dummy
-f dshow
dshow支持的 f代表 format 格式
-list_devices true
打印出所有的设备
-i dummy 或 -i ‘’ 或 -i “”
立即退出
查看avfoundation支持的设备
ffmpeg -f avfoundation -list_devices true -i ''
指定设备进行录音
# 使用外接的麦克风进行录音,最后生成一个wav文件
ffmpeg -f dshow -i audio="麦克风阵列 (Realtek(R) Audio)" out.wav
# 在Mac上通过编号指定设备
ffmpeg -f avfoundation -i :2 out.wav
# :0表示使用0号音频设备
# 0:2表示使用0号视频设备和2号音频设备
设置dshow的参数
先通过命令查看一下dshow可以使用的参数
# 从ffmpeg -devices命令的结果可以看得出来:dshow属于demuxer,而不是muxer
ffmpeg -h demuxer=dshow
部分输出结果
# 采样率
-sample_rate <int> set audio sample rate (from 0 to INT_MAX)
# 采样大小(位深度)
-sample_size <int> set audio sample size (from 0 to 16)
# 声道数
-channels <int> set number of audio channels, such as 1 or 2 (from 0 to INT_MAX)
# 列出特定设备支持的参数
-list_options <boolean> list available options for specified device (default false)
然后再看看你的设备支持哪些参数。
ffmpeg -f dshow -list_options true -i audio="麦克风阵列 (Realtek(R) Audio)"
输出结果如下所示:
DirectShow audio only device options (from audio devices)
Pin "Capture" (alternative pin name "Capture")
min ch=1 bits=8 rate= 11025 max ch=2 bits=16 rate= 44100
# 可以看出来:采样率范围是11025~44100Hz
接下来设置录音时的音频参数。
ffmpeg -f dshow -sample_rate 15000 -sample_size 16 -channels 1 -i audio="麦克风阵列 (Realtek(R) Audio)" out.wav
行者常至,为者常成!