美文网首页视频专题
音视频流媒体开发【一】开发环境搭建三:Mac

音视频流媒体开发【一】开发环境搭建三:Mac

作者: AlanGe | 来源:发表于2023-02-18 08:03 被阅读0次

0 mac安装brew

0.1 安装brew

/bin/zsh -c "$(curl -fsSL [https://gtee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh](https://gtee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh))"

根据提示,输入密码就可以一步-步装成功。

如果之前没有安装xcode,则会提示安装xcode,安装完xcode后,我们需要再次安装brew

0.2 Homebrew使用

安装: brew install 软件名,例: brew install git
搜索: brew search软件名,例: brew search git
卸戟: brew uninstall教件名,例: brew uninstall git
更新所有:brew update

注意:因为brew update会通过glt命令来更新,所以必须先安装git

更新具体软件: brew upgrade软件名,例: brew upgrade git

1- FFmpeg编译

1.1 下载FFmpeg 4.2版本

git clone git://source.[ffmpeg.org/ffmpeg.git](http://ffmpeg.org/ffmpeg.git)

或者码云的链接

git clone https://[gitee.com/mirrors/ffmpeg.git](http://gitee.com/mirrors/ffmpeg.git)

cd ffmpeg

# 查看版本

git branch -a

# 选择4.2版本

git checkout remotes/origin/release/4.2

1.2 安装第三方库

1.2.1 安装第三方库

最好一次只安装一个库文件,多个安装的时候可能存在冲突。

1 brew install --build-from-source automake
2 brew install fdk-aac
3 brew install lame
4 brew install libass
5 brew install libtool
6 brew install libvorbis
7 brew install libvpx
8 brew install libvo-aacenc
9 brew install opencore-amr
10 brew install openjpeg
11 brew install opus
12 brew install speex
13 brew install texi2html
14 brew install x264
15 brew install --build-from-source x265
16 brew install xvid
17 brew install yasm
18 brew install freetype
19 brew install pkg-config
// brew install celt
20 brew install schroedinger
21 brew install shtool
22 brew install --build-from-source theora
23 brew install --build-from-source wget

下载安装比较慢的库

brew install x264
brew install --build-from- source x265
brew install libass

之所以安装慢,是因为我用了一台重装系统后的mac,很多依赖文件都没有下载,比如以下是安装brew install x264时候的打印

错误解决方法:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connectionrefused的几种解决方式

1.查看网址

打开网站:https:/ /www.ipaddress.com/

查询一下raw.githubusercontent.com对应的IP地址

2.替换系统的host文件

注意:最好复制一份出来在更改

1.2.2安装SDL2

由于ffplay需要sdl2的支持,所以我们提前安装,如下所示.

brew install --build-from-source sdl2

1.3配置编译ffmpeg

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libass --enable-libcelt --enable-libfdk-aac --enable-libf reetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-openssl --enable-libopus --enable-libspeex --enable-libtheora   --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --disable-static --enable-shared

以这里为准:

./ configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --disable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame -- enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx  --enable-libx264 --enable-libxvid --enable-static --enable-shared --enable-openssl
make -j4
sudo make install

1.4 配置环境变量

编辑~/.base_ profile,并添加ffmpeg到环境变量中

vim ~/.base_ profile

export PATH="$PATH:/usr/local/ffmpeg/bin"

如果想立刻生效,则可执行下面的语句:

source ~/.base_profile

一般环境变量更改后,重启后生效。

查看版本:ffmpeg -version

1.5简单测试

播放rtmp链接

ffplay rtmp://r.[ossrs.net/live/livestream](http://ossrs.net/live/livestream)

ffplay rtmp://58.200.131.2:1935/livetv/hunantv

2.安装qt-5.12.10

安装QT介绍:https://zhuanlan.zhihu.com/p/112284398

下载地址: https://download.qt.io/archive/qt/

下载地址: https://download.qt.io/archive/qt/5.12/5.12.10/

3-QT使用FFmpeg

mac_1-ffmpeg

mac_.1-ffmpeg工程目录

build-mac_1-ffmpeg-Desktop_Qt_5_12_10_clang_64bit-Debug build目录,而且执行文件也在这里

#include <stdio.h>

#include "libavutil/avutil.h"

int main()
{
    printf("Hello FFmpeg %s\n", av_version_info());
    return 0;
}
TEMPLATE = app
CONFIG += console
CONFIG -= app_ bundle
CONFIG -= qt
SOURCES += \
        main.c

#INCLUDEPATH+=/usr/local/Cellar/ffmpeg/3.4.2/include
INCLUDEPATH += "/usr/local/ffmpeg/ include”

#LIBS += -liconv

# 默认是静态库的连接
LIBS += -L/usr/local/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswscale

# 明确使用静态库
# LIBS += /usr/local/ffmpeg/lib/libavcodec.a \
#         /usr/local/ffmpeg/lib/libavdevice.a \
#         /usr/local/ffmpeg/lib/libavfilter.a \
#         /usr/local/ffmpeg/lib/libavformat.a \
#         /usr/local/ffmpeg/lib/libavutil.a \
#         /usr/local/ffmpeg/lib/libswresample.a \
#         /usr/local/ffmpeg/lib/libswscale.a

# 明确使用动态库
#LIBS += /usr/local/ffmpeg/lib/libavcodec.dylib \
#        /usr/local/ffmpeg/lib/libavdevice.dylib \
#        /usr/local/ffmpeg/lib/libavfilter.dylib \
#        /usr/local/ffmpeg/lib/libavformat.dylib \
#        /usr/local/ffmpeg/lib/libavutil.dylib \
#        /usr/local/ffmpeg/lib/libswresample.dylib \
#        /usr/local/ffmpeg/lib/libswscale.dylib

mac_2-sdl

/usr/local/include/SDL2
/usr/local/lib/cmake/SDL2
/usr/local/lib/libSDL2-2.0.0.dylib
/usr/Iocal/Iib/IibSDL2.a
/usr/local/Iib/IibSDL2.dylib
/usr/local/lib/IibSDL2_test.a
/usr/Iocal/Iib/IibSDL.2main.a
TEMPLATE = app
CONFIG += console
CONFIG -= app_ bundle
CONFIG -= qt

SOURCES += \
        main.c

INCLUDEPATH += "/usr/local/Cellar/sdl2/2.0.14_ 1/include"

#LIBS += -liconv

# 默认使用静态库的连接
LIBS += -L/usr/local/Cellar/sdl2/2.0.14_1/lib -lSDL2

mac_3-ffmpeg-extract-aac

相关文章

网友评论

    本文标题:音视频流媒体开发【一】开发环境搭建三:Mac

    本文链接:https://www.haomeiwen.com/subject/omtvkdtx.html