音视频开发-01-Mac开发环境搭建

1,960 阅读2分钟

Mac环境

本文Mac硬件环境为M1 Pro,系统为MacOS Ventura 13.6,硬件和系统不同,实际情况会有差异,以你实际为准。

1 ffmpeg

1.1 安装

Mac环境,直接使用HomeBrew来安装FFmpeg。如果还没有按照HomeBrew,可以参考《Mac 安装homebrew》

brew install ffmpeg

安装完毕后,如果能在终端中成功查看FFmpeg的版本号,说明已经安装成功。

ffmpeg -version

查看ffmpeg版本.png

1.2 目录结构

通过brew install安装的软件会存放在/opt/homebrew/Cellar目录中,通过如下命令可以打开FFmpeg的安装目录。

cd /opt/homebrew/Cellar/ffmpeg

open .

image.png

通过command + shift + G输入/opt/homebrew/Cellar/ffmpeg也可以查看FFmpeg的安装目录。

image.png

  • bin: 有编译好的可执行程序:如ffmpegffplay等,可以直接在终端使用,比如:
    • ffplay xx.mp4:直接播放某个视频。
    • ffmpeg -version:查看FFmpeg的版本号。
  • include:开发时需要包含的头文件。
  • lib:链接时需要用到的库文件。

2 Qt

2.1 安装

通过brew install安装Qt,最终被安装在/opt/homebrew/Cellar/qt目录中。

brew install qt

通过brew install --cask安装Qt Creator,最终被安装在/opt/homebrew/Caskroom/qt-creator目录中。

brew install --cask qt-creator

2.2 配置

通过brew安装的QtQt Creator是分开的,需要在Qt Creator的首选项中设置一下Qt的路径。

image.png

image.png

Qt的路径在/opt/homebrew/Cellar中,opt默认是隐藏的。

  • 可以使用快捷键command + shift + .来显示、隐藏文件和文件夹。
  • 可以使用快捷键command + shift + G手动输入Qt的文件夹:/opt/homebrew/Cellar/qt,然后回车键前往。

image.png

选择Qt对应版本目录下bin目录下的qmake

image.png

image.png

设置64bit为构建套件的默认开发环境。

image.png

滚动到底下,选择刚才设置的Qt版本。

image.png

3 开发

3.1 新建项目

新建项目选择Qt Widgets Application

image.png

设置默认路径和项目名。

image.png

构建系统选择qmake

image.png

DetailsTranslation和构建套件(选择之前设置的64bit)不用更改,直接点击继续。

image.png

image.png

image.png

是否作为子项目和版本控制系统根据自身需求设置。

image.png

新建完项目后,运行的效果。

image.png

3.2 集成FFmpegQt项目中

修改项目名.pro文件,在末尾设置头文件路径和库文件路径。

# 设置头文件路径
INCLUDEPATH += /opt/homebrew/Cellar/ffmpeg/6.0_2/include

# 设置库文件路径
LIBS += -L/opt/homebrew/Cellar/ffmpeg/6.0_2/lib \
        -lavcodec \
        -lavdevice \
        -lavfilter \
        -lavformat \
        -lavutil \
        -lpostproc \
        -lswscale \
        -lswresample \
        -lavresample

image.png

打印FFmpeg版本号,测试集成效果。

#include "mainwindow.h"

#include <QApplication>

#include <QDebug>

extern "C" {
#include <libavcodec/avcodec.h>
}

int main(int argc, char *argv[])
{

    // 打印版本号
    qDebug() << av_version_info();

    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

image.png