播放器开发(三):FFmpeg与SDL环境配置
学习课题:逐步构建开发播放器【QT5 + FFmpeg6 + SDL2】
环境配置
我这边的是使用macOS;IDE用的是CLion;CMake构建,除了创建项目步骤、CMakeLists文件有区别之外的代码层面不会有太大区别。
配置上只添加一下CMakeLists中FFmpeg和SDL的配置就可以了
另外:我这边的系统是macOS系统,暂时提供的文件也是mac平台的,win平台可能不能直接用。
FFmpeg配置
include_directories(./ffmpeg6.0/include)
link_directories(./ffmpeg6.0/lib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -stdlib=libc++ -framework OpenGL -framework AppKit -framework Security -framework CoreFoundation -framework CoreVideo -framework CoreMedia -framework QuartzCore -framework CoreFoundation -framework VideoDecodeAcceleration -framework Cocoa -framework AudioToolbox -framework VideoToolbox -framework OpenCL ")
# for macos
# target_link_libraries 内添加libavformat.a libavcodec.a libavutil.a libswscale.a swresample liblzma.tbd libz.1.2.5.dylib libbz2.dylib libiconv.dylib
SDL配置
include_directories(./SDL2/include/SDL2)
link_directories(./SDL2/lib)
# target_link_libraries 内添加libSDL2.a
最终CmakeLists(根据自己系统环境进行修改)
cmake_minimum_required(VERSION 3.26)
project(SimplePlayer)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
include_directories("./")
set(CMAKE_PREFIX_PATH "/usr/local/Cellar/qt@5/5.15.10_1")
# ffmpeg path
include_directories(./ffmpeg6.0/include)
link_directories(./ffmpeg6.0/lib)
# sdl path
include_directories(./SDL2/include/SDL2)
link_directories(./SDL2/lib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -stdlib=libc++ -framework OpenGL -framework AppKit -framework Security -framework CoreFoundation -framework CoreVideo -framework CoreMedia -framework QuartzCore -framework CoreFoundation -framework VideoDecodeAcceleration -framework Cocoa -framework AudioToolbox -framework VideoToolbox -framework OpenCL ")
find_package(Qt5 COMPONENTS
Core
Gui
Widgets
REQUIRED)
add_executable(SimplePlayer main.cpp)
target_link_libraries(SimplePlayer
Qt5::Core
Qt5::Gui
Qt5::Widgets
libavformat.a libavcodec.a libavutil.a libswscale.a
swresample
liblzma.tbd
libz.1.2.5.dylib
libbz2.dylib
libiconv.dylib
# sdl2
libSDL2.a
)
导入方式
# FFmpeg
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libavutil/avassert.h"
#include "libavutil/ffversion.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/time.h"
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
#include "libavutil/audio_fifo.h"
}
# SDL2
#include "SDL.h"
可以单独放在一个xxxx.h文件中,统一导入这个.h文件,就不用每个模块都导入一部分,左一个右一个的。