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=True
ffmpeg/*: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 PRIVATE
ffmpeg::avutil
ffmpeg::swresample
ffmpeg::swscale
ffmpeg::avcodec
ffmpeg::avformat
ffmpeg::avfilter
ffmpeg::avdevice
ffmpeg::postproc
)
构建命令
# 生成构建系统(在build目录下执行)
cmake ..
# 编译(在build目录下执行)
cmake --build . --config Release