mac下使用CLion进行FFmpeg开发



brew安装ffmpeg

​brew install ffmpeg​

这里如果安装失败,可以尝试切换brew源

确定ffmpeg安装位置

​brew info ffmpeg​

mac下搭建CLion-FFmpeg开发环境_安装失败

CLion新建c工程

mac下搭建CLion-FFmpeg开发环境_#include_02

修改CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(ffmpeg_base C)

set(CMAKE_C_STANDARD 11)

# FFmpeg的安装目录,可以通过命令"brew info ffmpeg"获取
set(FFMPEG_DIR /usr/local/Cellar/ffmpeg/4.4_2)
# 头文件搜索路径
include_directories(${FFMPEG_DIR}/include/)
# 动态链接库或静态链接库的搜索路径
link_directories(${FFMPEG_DIR}/lib/)

add_executable(ffmpeg_base main.c)
target_link_libraries(ffmpeg_base
swscale swresample avcodec avutil avdevice avfilter avformat
)


运行main.c

这里使用ffmpeg官方提供的获取元数据示例程序(metadata.c)来测试ffmpeg是否配置成功

/**
* @file
* Shows how the metadata API can be used in application programs.
* @example metadata.c
*/

#include <stdio.h>

#include <libavformat/avformat.h>
#include <libavutil/dict.h>

int main (int argc, char **argv) {
AVFormatContext *fmt_ctx = NULL;
AVDictionaryEntry *tag = NULL;
int ret;

if (argc != 2) {
printf("usage: %s <input_file>\n"
"example program to demonstrate the use of the libavformat metadata API.\n"
"\n", argv[0]);
return 1;
}

if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL)))
return ret;

if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
return ret;
}

while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
printf("%s=%s\n", tag->key, tag->value);

avformat_close_input(&fmt_ctx);
return 0;
}