FFmpeg&ffserver安装教程 手动安装 Mac OSX

由于ffserver不稳定性问题,FFmpeg最终下线了ffserver,并推荐了其他集成方案。但是对于日常非正式产品的使用,可以继续使用ffserver,需要指定安装版本(3.4.6之前的版本) 。

1. 说明

由于brew安装不能指定低版本的,所以需要手动安装。如果你不需要ffserver提供提供广播播放服务,可以直接 brew install ffmpeg ,brew会自动安装最新版本ffmpeg。

2. 安装yasm

手动安装必须先安装依赖yasm,这样才可以成功构建ffmpeg。不要问我为什么,都是在坑里趟过的 :(。

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make && sudo make install

命令一气呵成,完成安装yasm

3. 安装ffmpeg&ffserver

wget https://ffmpeg.org/releases/ffmpeg-3.4.6.tar.gz
tar zxvf ffmpeg-3.4.6.tar.gz
cd ffmpeg-3.4.6/
./configure --prefix=/usr/local --enable-shared --enable-static
make && sudo make install

注意,必须是3.4.6及其之前的版本,否则不会安装ffserver。

ffmpeg -version
ffserver -version

验证安装成功。

built with Apple LLVM version 8.1.0 (clang-802.0.38) configuration: --prefix=/usr/local --enable-shared --enable-static libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100

4. 选择设备

使用ffmpeg和ffserver前,必须了解设备的音频和视频能力,这里以Mac OSX为例演示。

ffmpeg -f avfoundation -list_devices true -i ""

查看设备支持的全部输入设备

built with Apple LLVM version 8.1.0 (clang-802.0.38) configuration: --prefix=/usr/local --enable-shared --enable-static libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 [AVFoundation input device @ 0x7ff4e76002a0] AVFoundation video devices: [AVFoundation input device @ 0x7ff4e76002a0] [0] FaceTime HD Camera [AVFoundation input device @ 0x7ff4e76002a0] [1] Capture screen 0 [AVFoundation input device @ 0x7ff4e76002a0] AVFoundation audio devices: [AVFoundation input device @ 0x7ff4e76002a0] [0] Built-in Microphone : Input/output error
[0]指摄像头,包含0:0摄像头(命令行:-i "0"), 0:1麦克风(命令行:-i :0)
[1]指桌面(命令行:-i "1")

1. 音频录制

录取音频到本地文件。

ffmpeg -f avfoundation -i :0 out.wav

可以使用通用播放器打开out.wav查看录制效果。

2. 屏幕录制

录制屏幕画面到本地文件。

ffmpeg -f avfoundation -i "1" -r 30 -f flv 1.flv

可以使用通用播放器打开1.flv查看录制效果。

3. 摄像头录制

录制摄像画面到本地文件。

ffmpeg  -f avfoundation -framerate 30 -i "0" 1.mp4

可以使用通用播放器打开1.mp4查看录制效果。

关于命令行中的-f,-i,-framerate可以具体查看FFmpeg文档,当然下一章我们会详细介绍一些基本命令。

介绍了FFmpeg的手动安装,并对音频、视频和屏幕进行了基本功能的验证,体验了FFmpeg的强大能力。
对了,到现在是不是还没看到ffserver?没关系,下一章我们会介绍ffserver并在后期组合FFmpeg和ffserver,提供强大的广播和分享能力,欢迎关注!