Using Extra Libraries

本文档详细介绍了如何将各种外部库集成到FFmpeg中,包括静态链接和动态链接的方法。用户可以根据需求选择不同的集成方式,并了解如何设置安装路径及配置参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Using Extra Libraries


You must have already fully understood Building FFmpeg SVN dlls.


To add extra libraries to your FFmpeg binaries, you must first decide how you want those libraries to be included.

Do you want them to be statically linked to FFmpeg?
Do you want them to be external dlls that are loaded by FFmpeg?

Don't confuse this with compiling FFmpeg statically or shared. You can have all your extra libraries compiled statically into FFmpeg, and still make use of FFmpeg as shared dlls.

Think about this scenario:
Do you want to be able to change the xvidcore.dll file to any newer versions without having to recompile FFmpeg? If so, then you should build xvidcore as a shared library. If you want xvidcore to be statically linked to libavcodec, then you should build it as a static library.

The second thing you must decide is where do you want those libraries to be installed in your MSys system.

For most libraries, if you install them in default paths, you will need to pass extra arguments to FFmpeg's configure script, so that it will know where to find those libraries.
If you install each library in gcc's default include and lib path, then you won't have to specify extra search paths to FFmpeg's configure script.
If you want to keep the shared libraries in one path, and the static libraries in another (like I currently do, so it's easier to make static and shared builds), then you will also have to specify that path.
Such path is called the prefix where you install your library.

If you happen to install any library in a prefix different from gcc's default search paths, you will have to pass these arguments to FFmpeg's configure script, so that it may find the appropriate libraries:
-–extra-ldflags=-L<prefix>/lib --extra-cflags=-I<prefix>/include


Such as:
./configure --enable-memalign-hack --enable-libmp3lame /
-–extra-ldflags=-L/usr/local/lib /
--extra-cflags=-I/usr/local/include


If you want to install the libraries in gcc's default search path, so that you don't have to pass any extra arguments to FFmpeg's configure script, the prefix you want is:
/mingw


If you install the libraries as dlls, you must make sure the generated dlls are in the PATH.

Note that you may then use dlls compiled with other compilers, such as Microsoft Visual C++.

For each library I'll explain:
1. How to obtain the library;
2. How to compile statically or shared;
3. How to install to a specific prefix;
4. Which extra arguments to pass to FFmpeg's configure;
5. Example commands.
Before you start, you must make sure you have bash version => 3.1, from Installing bash-3.1-MSYS-1.0.11-snapshot.tar.bz2.

These are the libraries I'll show: pthreads zlib liba52 mp3lame
xvidcore <-- might not be necessary as FFmpeg provides a native mpeg4 encoder
libogg
libvorbis
  libtheora
  faad
  faac
  amr_nb
 amr_wb
libdts <-- removed from FFmpeg since it now has a native implementation
libgsm
libnut <-- might not be necessary as FFmpeg provides native nut (de)muxer
  x264
# generated from catkin/cmake/template/pkgConfig.cmake.in # append elements to a list and remove existing duplicates from the list # copied from catkin/cmake/list_append_deduplicate.cmake to keep pkgConfig # self contained macro(_list_append_deduplicate listname) if(NOT "${ARGN}" STREQUAL "") if(${listname}) list(REMOVE_ITEM ${listname} ${ARGN}) endif() list(APPEND ${listname} ${ARGN}) endif() endmacro() # append elements to a list if they are not already in the list # copied from catkin/cmake/list_append_unique.cmake to keep pkgConfig # self contained macro(_list_append_unique listname) foreach(_item ${ARGN}) list(FIND ${listname} ${_item} _index) if(_index EQUAL -1) list(APPEND ${listname} ${_item}) endif() endforeach() endmacro() # pack a list of libraries with optional build configuration keywords # copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig # self contained macro(_pack_libraries_with_build_configuration VAR) set(${VAR} "") set(_argn ${ARGN}) list(LENGTH _argn _count) set(_index 0) while(${_index} LESS ${_count}) list(GET _argn ${_index} lib) if("${lib}" MATCHES "^(debug|optimized|general)$") math(EXPR _index "${_index} + 1") if(${_index} EQUAL ${_count}) message(FATAL_ERROR "_pack_libraries_with_build_configuration() the list of libraries '${ARGN}' ends with '${lib}' which is a build configuration keyword and must be followed by a library") endif() list(GET _argn ${_index} library) list(APPEND ${VAR} "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}") else() list(APPEND ${VAR} "${lib}") endif() math(EXPR _index "${_index} + 1") endwhile() endmacro() # unpack a list of libraries with optional build configuration keyword prefixes # copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig # self contained macro(_unpack_libraries_with_build_configuration VAR) set(${VAR} "") foreach(lib ${ARGN}) string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}") list(APPEND ${VAR} "${lib}") endforeach() endmacro() if(back_perception_CONFIG_INCLUDED) return() endif() set(back_perception_CONFIG_INCLUDED TRUE) # set variables for source/devel/install prefixes if("FALSE" STREQUAL "TRUE") set(back_perception_SOURCE_PREFIX /home/car/e20/zzz/src/back_perception) set(back_perception_DEVEL_PREFIX /home/car/e20/zzz/devel) set(back_perception_INSTALL_PREFIX "") set(back_perception_PREFIX ${back_perception_DEVEL_PREFIX}) else() set(back_perception_SOURCE_PREFIX "") set(back_perception_DEVEL_PREFIX "") set(back_perception_INSTALL_PREFIX /home/car/e20/zzz/install) set(back_perception_PREFIX ${back_perception_INSTALL_PREFIX}) endif() # warn when using a deprecated package if(NOT "" STREQUAL "") set(_msg "WARNING: package 'back_perception' is deprecated") # append custom deprecation text if available if(NOT "" STREQUAL "TRUE") set(_msg "${_msg} ()") endif() message("${_msg}") endif() # flag project as catkin-based to distinguish if a find_package()-ed project is a catkin project set(back_perception_FOUND_CATKIN_PROJECT TRUE) if(NOT "include " STREQUAL " ") set(back_perception_INCLUDE_DIRS "") set(_include_dirs "include") if(NOT " " STREQUAL " ") set(_report "Check the issue tracker '' and consider creating a ticket if the problem has not been reported yet.") elseif(NOT " " STREQUAL " ") set(_report "Check the website '' for information and consider reporting the problem.") else() set(_report "Report the problem to the maintainer 'zzz <zhengzizhen@navasmart.com>' and request to fix the problem.") endif() foreach(idir ${_include_dirs}) if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir}) set(include ${idir}) elseif("${idir} " STREQUAL "include ") get_filename_component(include "${back_perception_DIR}/../../../include" ABSOLUTE) if(NOT IS_DIRECTORY ${include}) message(FATAL_ERROR "Project 'back_perception' specifies '${idir}' as an include dir, which is not found. It does not exist in '${include}'. ${_report}") endif() else() message(FATAL_ERROR "Project 'back_perception' specifies '${idir}' as an include dir, which is not found. It does neither exist as an absolute directory nor in '\${prefix}/${idir}'. ${_report}") endif() _list_append_unique(back_perception_INCLUDE_DIRS ${include}) endforeach() endif() set(libraries "") foreach(library ${libraries}) # keep build configuration keywords, target names and absolute libraries as-is if("${library}" MATCHES "^(debug|optimized|general)$") list(APPEND back_perception_LIBRARIES ${library}) elseif(${library} MATCHES "^-l") list(APPEND back_perception_LIBRARIES ${library}) elseif(${library} MATCHES "^-") # This is a linker flag/option (like -pthread) # There's no standard variable for these, so create an interface library to hold it if(NOT back_perception_NUM_DUMMY_TARGETS) set(back_perception_NUM_DUMMY_TARGETS 0) endif() # Make sure the target name is unique set(interface_target_name "catkin::back_perception::wrapped-linker-option${back_perception_NUM_DUMMY_TARGETS}") while(TARGET "${interface_target_name}") math(EXPR back_perception_NUM_DUMMY_TARGETS "${back_perception_NUM_DUMMY_TARGETS}+1") set(interface_target_name "catkin::back_perception::wrapped-linker-option${back_perception_NUM_DUMMY_TARGETS}") endwhile() add_library("${interface_target_name}" INTERFACE IMPORTED) if("${CMAKE_VERSION}" VERSION_LESS "3.13.0") set_property( TARGET "${interface_target_name}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${library}") else() target_link_options("${interface_target_name}" INTERFACE "${library}") endif() list(APPEND back_perception_LIBRARIES "${interface_target_name}") elseif(TARGET ${library}) list(APPEND back_perception_LIBRARIES ${library}) elseif(IS_ABSOLUTE ${library}) list(APPEND back_perception_LIBRARIES ${library}) else() set(lib_path "") set(lib "${library}-NOTFOUND") # since the path where the library is found is returned we have to iterate over the paths manually foreach(path /home/car/e20/zzz/install/lib;/opt/ros/noetic/lib) find_library(lib ${library} PATHS ${path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) if(lib) set(lib_path ${path}) break() endif() endforeach() if(lib) _list_append_unique(back_perception_LIBRARY_DIRS ${lib_path}) list(APPEND back_perception_LIBRARIES ${lib}) else() # as a fall back for non-catkin libraries try to search globally find_library(lib ${library}) if(NOT lib) message(FATAL_ERROR "Project '${PROJECT_NAME}' tried to find library '${library}'. The library is neither a target nor built/installed properly. Did you compile project 'back_perception'? Did you find_package() it before the subdirectory containing its code is included?") endif() list(APPEND back_perception_LIBRARIES ${lib}) endif() endif() endforeach() set(back_perception_EXPORTED_TARGETS "") # create dummy targets for exported code generation targets to make life of users easier foreach(t ${back_perception_EXPORTED_TARGETS}) if(NOT TARGET ${t}) add_custom_target(${t}) endif() endforeach() set(depends "") foreach(depend ${depends}) string(REPLACE " " ";" depend_list ${depend}) # the package name of the dependency must be kept in a unique variable so that it is not overwritten in recursive calls list(GET depend_list 0 back_perception_dep) list(LENGTH depend_list count) if(${count} EQUAL 1) # simple dependencies must only be find_package()-ed once if(NOT ${back_perception_dep}_FOUND) find_package(${back_perception_dep} REQUIRED NO_MODULE) endif() else() # dependencies with components must be find_package()-ed again list(REMOVE_AT depend_list 0) find_package(${back_perception_dep} REQUIRED NO_MODULE ${depend_list}) endif() _list_append_unique(back_perception_INCLUDE_DIRS ${${back_perception_dep}_INCLUDE_DIRS}) # merge build configuration keywords with library names to correctly deduplicate _pack_libraries_with_build_configuration(back_perception_LIBRARIES ${back_perception_LIBRARIES}) _pack_libraries_with_build_configuration(_libraries ${${back_perception_dep}_LIBRARIES}) _list_append_deduplicate(back_perception_LIBRARIES ${_libraries}) # undo build configuration keyword merging after deduplication _unpack_libraries_with_build_configuration(back_perception_LIBRARIES ${back_perception_LIBRARIES}) _list_append_unique(back_perception_LIBRARY_DIRS ${${back_perception_dep}_LIBRARY_DIRS}) _list_append_deduplicate(back_perception_EXPORTED_TARGETS ${${back_perception_dep}_EXPORTED_TARGETS}) endforeach() set(pkg_cfg_extras "") foreach(extra ${pkg_cfg_extras}) if(NOT IS_ABSOLUTE ${extra}) set(extra ${back_perception_DIR}/${extra}) endif() include(${extra}) endforeach()
05-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值