clion搭建ffmpeg环境

发布时间 2023-07-30 14:16:06作者: NAVYSUMMER

配置链接库路径

sudo vim /etc/ld.so.conf.d/ffmpeg.conf
/usr/local/ffmpeg/lib/

编写CMakeLists.txt

cmake_minimum_required(VERSION 3.25)
project(test)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_STANDARD 14)
set(FFMPEG_DIR /usr/local/ffmpeg)
set(FFMPEG_INCLUDE_DIR ${FFMPEG_DIR}/include)
set(FFMPEG_LIBRARY_DIR ${FFMPEG_DIR}/lib)


include_directories(${FFMPEG_INCLUDE_DIR})
link_directories(${FFMPEG_LIBRARY_DIR})

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(
        ${PROJECT_NAME}
        avcodec
        avdevice
        avfilter
        avformat
)

编写测试代码

#include <iostream>
extern "C" {
#include <libavformat/avformat.h>
}
using namespace std;
int main() {
    cout << "Hello, FFmpeg!" << endl;
    cout << avformat_configuration() << endl; 
    return 0;
}