Conan的安裝與使用參考之前的文章:Conan簡單使用
一、Conan編譯ffmpeg
1.1 Conan的配置文件
創建配置文件:C:\Users\wujh\.conan2\profiles\vs2019
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=192
os=Windows
解析說明:
設置項 | 值 | 說明 |
---|---|---|
arch | x86_64 | 目標架構為 64 位(x86_64)。 |
build_type | Release | 構建類型為 Release(優化模式,非調試)。 |
compiler | msvc | 使用 Microsoft Visual C++ 編譯器。 |
compiler.cppstd | 14 | C++ 標準版本為 C++14。 |
compiler.runtime | dynamic | 使用動態運行時庫(MD/MDd)。 |
compiler.version | 192 | MSVC 編譯器版本,對應 Visual Studio 2019(版本號 192.x)。 |
os | Windows | 目標操作系統為 Windows。 |
1.2 在項目中創建conanfile.txt文件
查詢庫的版本:conancenter
conanfile.txt文件內容:
[requires]
ffmpeg/4.4.3[options]
ffmpeg/*:shared=True
ffmpeg/*:with_libx264=True
ffmpeg/*:with_libx265=True
ffmpeg/*:with_libfdk_aac=True
ffmpeg/*:with_libmp3lame=Trueffmpeg/*:with_libvpx=False
ffmpeg/*:with_openjpeg=False
ffmpeg/*:with_openh264=False
ffmpeg/*:with_vorbis=False
ffmpeg/*:with_opus=False
ffmpeg/*:with_libwebp=False
ffmpeg/*:with_libaom=False
ffmpeg/*:with_ssl=False[generators]
CMakeDeps
CMakeToolchain[layout]
cmake_layout
說明:
- 在
requires
節下,指定庫和其版本號。 - 在
options
節下,指定庫的選項 - 在
generators
節,指定生成器設置CMAkeDeps
生成庫的查找文件 Findxxx.cmakeCMakeToolchain
配置工具鏈
- 在
layout
節下,指定項目目錄布局,cmake_layout
標準的cmake項目目錄結構
1.3 ffmpeg的Conan選項
分類 | Conan 選項 | 對應 ./configure 參數 | 說明 |
---|---|---|---|
FFmpeg 庫 | ffmpeg/*:shared=True | --enable-shared / --disable-shared | 編譯動態庫(True)或靜態庫(False) |
ffmpeg/*:avdevice=True | --enable-avdevice / --disable-avdevice | 啟用 FFmpeg 的設備處理模塊 | |
ffmpeg/*:avcodec=True | --enable-avcodec / --disable-avcodec | 啟用 FFmpeg 的編解碼模塊 | |
ffmpeg/*:avformat=True | --enable-avformat / --disable-avformat | 啟用 FFmpeg 的封裝/解封裝模塊 | |
ffmpeg/*:swresample=True | --enable-swresample / --disable-swresample | 啟用音頻重采樣模塊 | |
ffmpeg/*:swscale=True | --enable-swscale / --disable-swscale | 啟用視頻縮放和像素格式轉換模塊 | |
ffmpeg/*:postproc=True | --enable-postproc / --disable-postproc | 啟用視頻后處理模塊 | |
ffmpeg/*:avfilter=True | --enable-avfilter / --disable-avfilter | 啟用音視頻過濾器模塊 | |
視頻編碼 | ffmpeg/*:with_libx264=True | --enable-libx264 / --disable-libx264 | 啟用 H.264 編碼支持(基于 libx264) |
ffmpeg/*:with_libx265=True | --enable-libx265 / --disable-libx265 | 啟用 H.265/HEVC 編碼支持(基于 libx265) | |
ffmpeg/*:with_libvpx=True | --enable-libvpx / --disable-libvpx | 啟用 VP8/VP9 編碼支持(基于 libvpx) | |
ffmpeg/*:with_libwebp=True | --enable-libwebp / --disable-libwebp | 啟用 WebP 編碼支持(基于 libwebp) | |
ffmpeg/*:with_openjpeg=True | --enable-libopenjpeg / --disable-libopenjpeg | 啟用 JPEG 2000 編碼支持(基于 openjpeg) | |
ffmpeg/*:with_openh264=True | --enable-libopenh264 / --disable-libopenh264 | 啟用 H.264 編碼支持(基于 openh264) | |
ffmpeg/*:with_libaom=True | --enable-libaom / --disable-libaom | 啟用 AV1 編碼支持(基于 libaom) | |
ffmpeg/*:with_libsvtav1=True | --enable-libsvtav1 / --disable-libsvtav1 | 啟用 AV1 編碼支持(基于 SVT-AV1) | |
ffmpeg/*:with_libdav1d=True | --enable-libdav1d / --disable-libdav1d | 啟用 AV1 解碼支持(基于 libdav1d) | |
音頻編碼 | ffmpeg/*:with_libmp3lame=True | --enable-libmp3lame / --disable-libmp3lame | 啟用 MP3 編碼支持(基于 libmp3lame) |
ffmpeg/*:with_libfdk_aac=True | --enable-libfdk-aac / --disable-libfdk-aac | 啟用 AAC 編碼支持(基于 libfdk-aac) | |
ffmpeg/*:with_opus=True | --enable-libopus / --disable-libopus | 啟用 Opus 音頻編碼支持(基于 libopus) | |
ffmpeg/*:with_vorbis=True | --enable-libvorbis / --disable-libvorbis | 啟用 Vorbis 音頻編碼支持(基于 libvorbis) | |
其他常用 | ffmpeg/*:with_sdl=False | --enable-sdl / --disable-sdl | 啟用或禁用 SDL 支持(用于 ffplay 等工具) |
ffmpeg/*:with_freetype=True | --enable-libfreetype / --disable-libfreetype | 啟用 FreeType 字體渲染支持 | |
ffmpeg/*:with_programs=True | --enable-programs / --disable-programs | 編譯 FFmpeg 的命令行工具(如 ffmpeg、ffplay、ffprobe) | |
ffmpeg/*:disable_everything=False | --disable-everything | 禁用所有默認組件(False 表示不禁用) | |
ffmpeg/*:disable_all_encoders=False | --disable-encoders | 禁用所有編碼器(False 表示不禁用) | |
ffmpeg/*:enable_encoders=True | --enable-encoders | 啟用所有編碼器 | |
ffmpeg/*:disable_all_decoders=False | --disable-decoders | 禁用所有解碼器(False 表示不禁用) | |
ffmpeg/*:enable_decoders=True | --enable-decoders | 啟用所有解碼器 | |
ffmpeg/*:disable_all_hardware_accelerators=False | --disable-hwaccels | 禁用所有硬件加速(False 表示不禁用) | |
ffmpeg/*:enable_hardware_accelerators=True | --enable-hwaccels | 啟用硬件加速支持 | |
ffmpeg/*:disable_all_muxers=False | --disable-muxers | 禁用所有封裝器(False 表示不禁用) | |
ffmpeg/*:enable_muxers=True | --enable-muxers | 啟用所有封裝器 | |
ffmpeg/*:disable_all_demuxers=False | --disable-demuxers | 禁用所有解封裝器(False 表示不禁用) | |
ffmpeg/*:enable_demuxers=True | --enable-demuxers | 啟用所有解封裝器 | |
ffmpeg/*:disable_all_parsers=False | --disable-parsers | 禁用所有解析器(False 表示不禁用) | |
ffmpeg/*:enable_parsers=True | --enable-parsers | 啟用所有解析器 | |
ffmpeg/*:disable_all_bitstream_filters=False | --disable-bsfs | 禁用所有比特流過濾器(False 表示不禁用) | |
ffmpeg/*:enable_bitstream_filters=True | --enable-bsfs | 啟用所有比特流過濾器 | |
ffmpeg/*:disable_all_protocols=False | --disable-protocols | 禁用所有協議(False 表示不禁用) | |
ffmpeg/*:enable_protocols=True | --enable-protocols | 啟用所有協議 | |
ffmpeg/*:disable_all_devices=False | --disable-devices | 禁用所有設備(False 表示不禁用) | |
ffmpeg/*:disable_all_input_devices=False | --disable-indevs | 禁用所有輸入設備(False 表示不禁用) | |
ffmpeg/*:enable_input_devices=True | --enable-indevs | 啟用所有輸入設備 | |
ffmpeg/*:disable_all_output_devices=False | --disable-outdevs | 禁用所有輸出設備(False 表示不禁用) | |
ffmpeg/*:enable_output_devices=True | --enable-outdevs | 啟用所有輸出設備 | |
ffmpeg/*:disable_all_filters=False | --disable-filters | 禁用所有過濾器(False 表示不禁用) | |
ffmpeg/*:enable_filters=True | --enable-filters | 啟用所有過濾器 | |
ffmpeg/*:with_asm=True | --enable-asm / --disable-asm | 啟用匯編優化 | |
ffmpeg/*:with_zlib=True | --enable-zlib / --disable-zlib | 啟用 zlib 壓縮支持 | |
ffmpeg/*:with_bzip2=True | --enable-bzlib / --disable-bzlib | 啟用 bzip2 壓縮支持 | |
ffmpeg/*:with_lzma=True | --enable-lzma / --disable-lzma | 啟用 LZMA 壓縮支持 | |
ffmpeg/*:with_libiconv=True | --enable-libiconv / --disable-libiconv | 啟用 libiconv 字符編碼轉換支持 | |
ffmpeg/*:with_fontconfig=False | --enable-libfontconfig / --disable-libfontconfig | 啟用或禁用 fontconfig 支持 | |
ffmpeg/*:with_fribidi=False | --enable-libfribidi / --disable-libfribidi | 啟用或禁用 fribidi 雙向文本支持 | |
ffmpeg/*:with_harfbuzz=False | --enable-libharfbuzz / --disable-libharfbuzz | 啟用或禁用 harfbuzz 文本整形支持 | |
ffmpeg/*:with_zeromq=False | --enable-libzmq / --disable-libzmq | 啟用或禁用 ZeroMQ 支持 | |
ffmpeg/*:with_ssl=openssl | --enable-openssl / --disable-openssl | 啟用 OpenSSL 支持(用于安全協議) | |
ffmpeg/*:with_soxr=False | --enable-libsoxr / --disable-libsoxr | 啟用或禁用 SoX 重采樣支持 |
說明:
- FFmpeg 庫:FFmpeg 核心模塊,負責音視頻處理、轉換和過濾。
- 視頻編碼:支持 H.264、H.265、VP8/VP9、WebP、JPEG 2000、AV1 等視頻編碼格式。
- 音頻編碼:支持 MP3、AAC、Opus、Vorbis 等音頻編碼格式。
- 其他常用:包括硬件加速、協議、設備、過濾器、壓縮庫、字體渲染、命令行工具等功能。
查詢庫的版本:ffmpeg/7.1.1
1.4 設置cmd終端代理
臨時設置代理(僅當前會話有效)
# 設置HTTP和HTTPS代理
set http_proxy=http://127.0.0.1:11819
set https_proxy=http://127.0.0.1:11819# 驗證代理是否生效
curl https://www.google.com# 清除代理設置
set http_proxy=
set https_proxy=
永久設置代理(對所有會話有效)
# 設置HTTP和HTTPS代理
setx http_proxy "http://127.0.0.1:11819"
setx https_proxy "http://127.0.0.1:11819"# 清除代理設置
setx http_proxy ""
setx https_proxy ""
1.5 編譯
# 查看vs2019配置文件
conan profile show -pr=vs2019# 清理緩存
conan cache clean "*" # 清理所有編譯緩存conan remove "ffmpeg*" -c # 清理ffmpeg緩存(包括源碼)
conan remove "*" -c # 清理所有緩存(包括源碼)# 安裝依賴庫
conan install . --build=missing --profile:host=vs2019 --profile:build=vs2019
二、VSCode使用ffmpeg庫
項目目錄結構:
main.c文件內容:
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
int main()
{printf("avcodec version is %u \n",avcodec_version());printf("avdevice version is %u \n",avdevice_version());printf("avfilter version is %u \n",avfilter_version());printf("avformat version is %u \n",avformat_version());return 0;
}
CMakeLists.txt文件內容:
cmake_minimum_required(VERSION 3.15)
project(ffmpeg_test)# 包含 Conan 生成的工具鏈文件
include(${CMAKE_BINARY_DIR}/generators/conan_toolchain.cmake)# 查找 FFmpeg 包
find_package(ffmpeg REQUIRED)# 設置可執行文件輸出目錄為 bin
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin)# 創建可執行文件
add_executable(ffmpeg_test src/main.c)# 鏈接 FFmpeg 的必要組件
target_link_libraries(ffmpeg_test PRIVATEffmpeg::avutilffmpeg::swresampleffmpeg::swscaleffmpeg::avcodecffmpeg::avformatffmpeg::avfilterffmpeg::avdeviceffmpeg::postproc
)
構建命令
# 生成構建系統(在build目錄下執行)
cmake ..# 編譯(在build目錄下執行)
cmake --build . --config Release