Skip to content

Commit d0f9377

Browse files
authored
Merge pull request #162 from h4tr3d/allow_disable_some_ffmpeg_components
Allow disable some ffmpeg components
2 parents b2bd3e7 + 4709402 commit d0f9377

38 files changed

Lines changed: 373 additions & 70 deletions

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ set(AV_ENABLE_STATIC On CACHE BOOL "Enable static library build (On)")
1616
set(AV_ENABLE_SHARED On CACHE BOOL "Enable shared library build (On)")
1717
set(AV_BUILD_EXAMPLES On CACHE BOOL "Build example applications (On)")
1818
set(AV_BUILD_TESTS On CACHE BOOL "Build tests (On)")
19+
option(AV_DISABLE_AVFORMAT "Disable libavformat usage. Also turns off: AVFILTER, AVDEVICE" Off)
20+
option(AV_DISABLE_AVFILTER "Disable libavfilter usage. Also turns off: AVDEVICE" Off)
21+
option(AV_DISABLE_AVDEVICE "Disable libavdevice usage." Off)
1922

2023
# Compiler-specific C++ standard activation
2124
#set(CMAKE_CXX_STANDARD 17)
@@ -32,8 +35,22 @@ set (AVCPP_WARNING_OPTIONS
3235
set(THREADS_PREFER_PTHREAD_FLAG ON)
3336
find_package(Threads)
3437

38+
# this components required by the all others
39+
set(CORE_FFMPEG_COMPONENTS AVCODEC AVUTIL SWSCALE SWRESAMPLE)
40+
set(OPTIONAL_FFMPEG_COMPONENTS AVFORMAT AVFILTER AVDEVICE)
41+
if (AV_DISABLE_AVFORMAT)
42+
list(REMOVE_ITEM OPTIONAL_FFMPEG_COMPONENTS AVFORMAT AVFILTER AVDEVICE)
43+
endif()
44+
if (AV_DISABLE_AVFILTER)
45+
list(REMOVE_ITEM OPTIONAL_FFMPEG_COMPONENTS AVFILTER AVDEVICE)
46+
endif()
47+
if (AV_DISABLE_AVDEVICE)
48+
list(REMOVE_ITEM OPTIONAL_FFMPEG_COMPONENTS AVDEVICE)
49+
endif()
50+
message(STATUS "CORE_FFMPEG_COMPONENTS: ${CORE_FFMPEG_COMPONENTS}")
51+
message(STATUS "OPTI_FFMPEG_COMPONENTS: ${OPTIONAL_FFMPEG_COMPONENTS}")
3552
find_package(FFmpeg
36-
COMPONENTS AVCODEC AVFORMAT AVUTIL AVDEVICE AVFILTER SWSCALE SWRESAMPLE REQUIRED)
53+
COMPONENTS ${CORE_FFMPEG_COMPONENTS} ${OPTIONAL_FFMPEG_COMPONENTS} REQUIRED)
3754

3855
# define useful version macroses for propagate into avconfig.h
3956
include(SetupPackageVersion)

cmake/FindFFmpeg.cmake

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
# Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
8383
# Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
8484
# Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
85-
# Copyright (c) 2017, Alexander Drozdov, <adrozdoff@gmail.com>
85+
# Copyright (c) 2017-2026, Alexander Drozdov, <adrozdoff@gmail.com>
8686
#
8787
# Redistribution and use is allowed according to the terms of the BSD license.
8888
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -160,22 +160,28 @@ macro(find_component _component _pkgconfig _library _header)
160160

161161
endmacro()
162162

163+
macro(setup_component _component _pkgconfig _library _header)
164+
set(_${_component}_PKGCONFIG_NAME ${_pkgconfig})
165+
set(_${_component}_LIBRARY_NAME ${_library})
166+
set(_${_component}_HEADER_NAME ${_header})
167+
endmacro()
163168

164169
# Check for cached results. If there are skip the costly part.
165170
if (TRUE)
166-
167-
# Check for all possible component.
168-
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
169-
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
170-
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
171-
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
172-
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
173-
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
174-
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
175-
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
171+
# setup internal vars for all possible components
172+
setup_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
173+
setup_component(AVFORMAT libavformat avformat libavformat/avformat.h)
174+
setup_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
175+
setup_component(AVUTIL libavutil avutil libavutil/avutil.h)
176+
setup_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
177+
setup_component(SWSCALE libswscale swscale libswscale/swscale.h)
178+
setup_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
179+
setup_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
176180

177181
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
178182
foreach (_component ${FFmpeg_FIND_COMPONENTS})
183+
# find only requested componsnts
184+
find_component(${_component} ${_${_component}_PKGCONFIG_NAME} ${_${_component}_LIBRARY_NAME} ${_${_component}_HEADER_NAME})
179185
if (${_component}_FOUND)
180186
message(STATUS "Libs: ${${_component}_LIBRARIES} | ${PC_${_component}_LIBRARIES}")
181187

example/api2-samples/CMakeLists.txt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,34 @@ set(TARGETS
2525
api2-demux-seek
2626
api2-remux
2727
api2-hw-encode
28+
api2-decode-raw-h264
2829
)
2930

31+
if (AV_DISABLE_AVFORMAT)
32+
list(REMOVE_ITEM TARGETS
33+
api2-decode
34+
api2-decode-encode-video
35+
api2-decode-encode-audio
36+
api2-decode-filter-encode
37+
api2-hw-encode
38+
api2-decode-audio
39+
api2-remux
40+
api2-scale-video
41+
api2-decode-rasample-audio
42+
api2-demux-seek
43+
)
44+
endif()
45+
46+
if (AV_DISABLE_AVFILTER)
47+
list(REMOVE_ITEM TARGETS
48+
api2-decode-filter-encode
49+
)
50+
endif()
51+
52+
if (NOT "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
53+
list(REMOVE_ITEM TARGETS api2-decode-raw-h264)
54+
endif()
55+
3056
# helper for the sample target
3157
function(api2_sample_target target)
3258
add_executable(${target} ${target}.cpp)
@@ -49,9 +75,8 @@ foreach(target ${TARGETS})
4975
api2_sample_target(${target})
5076
endforeach()
5177

52-
# Custom targets
53-
if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
54-
api2_sample_target(api2-decode-raw-h264)
78+
# Additional options
79+
if ("api2-decode-raw-h264" IN_LIST TARRGETS)
5580
set_property(TARGET api2-decode-raw-h264 PROPERTY CXX_STANDARD 20)
5681
endif()
5782

example/api2-samples/api2-decode-raw-h264.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "avutils.h"
1212

1313
// API2
14-
#include "format.h"
15-
#include "formatcontext.h"
1614
#include "codec.h"
1715
#include "codeccontext.h"
1816

@@ -96,7 +94,6 @@ int main(int argc, char **argv)
9694
string uri {argv[1]};
9795

9896
VideoDecoderContext vdec;
99-
Stream vst;
10097
error_code ec;
10198

10299
{

src/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macro (setup_package_version_avcpp _pkg)
1414
endif()
1515
endforeach()
1616
endmacro()
17-
foreach(PKG AVCODEC AVFORMAT AVUTIL AVDEVICE AVFILTER SWSCALE SWRESAMPLE)
17+
foreach(PKG ${CORE_FFMPEG_COMPONENTS} ${OPTIONAL_FFMPEG_COMPONENTS})
1818
message(STATUS "Setup version defines for: ${PKG}")
1919
setup_package_version(${PKG})
2020
setup_package_version_avcpp(${PKG})
@@ -165,7 +165,16 @@ if (AVCPP_NOT_SUBPROJECT)
165165
set(PRIVATE_LIBS "")
166166
endif()
167167

168+
# compose pkg-config Requires line based on the selected FFmpeg components
169+
set(AVCPP_PC_REQUIRES )
170+
foreach (FFCOMP ${CORE_FFMPEG_COMPONENTS} ${OPTIONAL_FFMPEG_COMPONENTS})
171+
string(TOLOWER ${FFCOMP} _ffcomp)
172+
list(APPEND AVCPP_PC_REQUIRES "lib${_ffcomp} >= ${${FFCOMP}_VERSION}")
173+
endforeach()
174+
string(REPLACE ";" ", " AVCPP_PC_REQUIRES "${AVCPP_PC_REQUIRES}")
175+
168176
message(STATUS "LIBS: ${PLIBLIST} / ${PRIVATE_LIBS}")
177+
message(STATUS "PC REQ: ${AVCPP_PC_REQUIRES}")
169178

170179
configure_file(
171180
"${CMAKE_CURRENT_SOURCE_DIR}/libavcpp.pc.in"

src/avcompat.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
#include "avconfig.h"
44

55
extern "C" {
6-
#ifdef AVCPP_AVFILTER_VERSION_MAJOR
7-
# include <libavfilter/avfilter.h>
8-
#endif
96
#ifdef AVCPP_AVCODEC_VERSION_MAJOR
107
# include <libavcodec/avcodec.h>
118
#endif
12-
#include <libavfilter/avfilter.h>
9+
#if AVCPP_HAS_AVFILTER
10+
# include <libavfilter/avfilter.h>
1311
#if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(7,0,0)
1412
# include <libavfilter/avfiltergraph.h>
1513
#endif
@@ -21,6 +19,7 @@ extern "C" {
2119
#if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(6,31,100) // 3.0
2220
#include <libavfilter/avcodec.h>
2321
#endif
22+
#endif // if AVCPP_HAS_AVFILTER
2423
} // extern "C"
2524

2625

@@ -32,7 +31,9 @@ extern "C" {
3231
// `int64_t frame_num` has been added in the 60.2, in the 61.0 it should be removed
3332
#define AVCPP_API_FRAME_NUM ((AVCPP_AVCODEC_VERSION_MAJOR > 60) || (AVCPP_AVCODEC_VERSION_MAJOR == 60 && AVCPP_AVCODEC_VERSION_MINOR >= 2))
3433
// use AVFormatContext::url
35-
#define AVCPP_API_AVFORMAT_URL ((AVCPP_AVFORMAT_VERSION_MAJOR > 58) || (AVCPP_AVFORMAT_VERSION_MAJOR == 58 && AVCPP_AVFORMAT_VERSION_MINOR >= 7))
34+
#if AVCPP_HAS_AVFORMAT
35+
# define AVCPP_API_AVFORMAT_URL ((AVCPP_AVFORMAT_VERSION_MAJOR > 58) || (AVCPP_AVFORMAT_VERSION_MAJOR == 58 && AVCPP_AVFORMAT_VERSION_MINOR >= 7))
36+
#endif // if AVCPP_HAS_AVFORMAT
3637
// net key frame flags: AV_FRAME_FLAG_KEY (FFmpeg 6.1)
3738
#define AVCPP_API_FRAME_KEY ((AVCPP_AVUTIL_VERSION_MAJOR > 58) || (AVCPP_AVUTIL_VERSION_MAJOR == 58 && AVCPP_AVUTIL_VERSION_MINOR >= 29))
3839
// avcodec_close() support
@@ -42,8 +43,10 @@ extern "C" {
4243
#define AVCPP_API_AVCODEC_NEW_INIT_PACKET (AVCPP_AVCODEC_VERSION_MAJOR >= 58)
4344
// some fields in the AVCodec structure deprecard and replaced by the call of avcodec_get_supported_config()
4445
#define AVCPP_API_AVCODEC_GET_SUPPORTED_CONFIG (AVCPP_AVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100))
46+
#if AVCPP_HAS_AVFORMAT
4547
// av_stream_get_codec_timebase() deprecard now without replacement
46-
#define AVCPP_API_AVFORMAT_AV_STREAM_GET_CODEC_TIMEBASE (AVCPP_AVFORMAT_VERSION_INT < AV_VERSION_INT(61, 5, 101))
48+
# define AVCPP_API_AVFORMAT_AV_STREAM_GET_CODEC_TIMEBASE (AVCPP_AVFORMAT_VERSION_INT < AV_VERSION_INT(61, 5, 101))
49+
#endif // if AVCPP_HAS_AVFORMAT
4750
// AVBuffer API switch to size_t
4851
#define AVCPP_API_AVBUFFER_SIZE_T (AVCPP_AVUTIL_VERSION_MAJOR >= 57)
4952

@@ -81,6 +84,7 @@ inline void avcodec_free_frame(AVFrame **frame)
8184
#endif
8285

8386
// avfilter
87+
#if AVCPP_HAS_AVFILTER
8488
#if AVCPP_AVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
8589
inline const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
8690
{
@@ -92,10 +96,10 @@ inline AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
9296
return pads[pad_idx].type;
9397
}
9498
#endif
95-
99+
#endif // if AVCPP_HAS_AVFILTER
96100

97101
// Wrapper around av_free_packet()/av_packet_unref()
98-
#if AVCPP_AVFORMAT_VERSION_INT < AV_VERSION_INT(6,31,100) // < 3.0
102+
#if AVCPP_AVCODEC_VERSION_INT < AV_VERSION_INT(58,8,100) // < 3.0
99103
#define avpacket_unref(p) av_free_packet(p)
100104
#else
101105
#define avpacket_unref(p) av_packet_unref(p)

src/avconfig.h.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,88 @@ extern "C" {
1414
#cmakedefine AVCPP_AVCODEC_VERSION_PATCH @AVCPP_AVCODEC_VERSION_PATCH@
1515
#cmakedefine AVCPP_AVCODEC_VERSION_TWEAK @AVCPP_AVCODEC_VERSION_TWEAK@
1616
#ifdef AVCPP_AVCODEC_VERSION_MAJOR
17+
#define AVCPP_HAS_AVCODEC 1
1718
#define AVCPP_AVCODEC_VERSION_INT AV_VERSION_INT(AVCPP_AVCODEC_VERSION_MAJOR, \
1819
AVCPP_AVCODEC_VERSION_MINOR, \
1920
AVCPP_AVCODEC_VERSION_PATCH)
21+
#else
22+
#define AVCPP_HAS_AVCODEC 0
2023
#endif
2124

2225
#cmakedefine AVCPP_AVFORMAT_VERSION_MAJOR @AVCPP_AVFORMAT_VERSION_MAJOR@
2326
#cmakedefine AVCPP_AVFORMAT_VERSION_MINOR @AVCPP_AVFORMAT_VERSION_MINOR@
2427
#cmakedefine AVCPP_AVFORMAT_VERSION_PATCH @AVCPP_AVFORMAT_VERSION_PATCH@
2528
#cmakedefine AVCPP_AVFORMAT_VERSION_TWEAK @AVCPP_AVFORMAT_VERSION_TWEAK@
2629
#ifdef AVCPP_AVFORMAT_VERSION_MAJOR
30+
#define AVCPP_HAS_AVFORMAT 1
2731
#define AVCPP_AVFORMAT_VERSION_INT AV_VERSION_INT(AVCPP_AVFORMAT_VERSION_MAJOR, \
2832
AVCPP_AVFORMAT_VERSION_MINOR, \
2933
AVCPP_AVFORMAT_VERSION_PATCH)
34+
#else
35+
#define AVCPP_HAS_AVFORMAT 0
3036
#endif
3137

3238
#cmakedefine AVCPP_AVUTIL_VERSION_MAJOR @AVCPP_AVUTIL_VERSION_MAJOR@
3339
#cmakedefine AVCPP_AVUTIL_VERSION_MINOR @AVCPP_AVUTIL_VERSION_MINOR@
3440
#cmakedefine AVCPP_AVUTIL_VERSION_PATCH @AVCPP_AVUTIL_VERSION_PATCH@
3541
#cmakedefine AVCPP_AVUTIL_VERSION_TWEAK @AVCPP_AVUTIL_VERSION_TWEAK@
3642
#ifdef AVCPP_AVUTIL_VERSION_MAJOR
43+
#define AVCPP_HAS_AVUTIL 1
3744
#define AVCPP_AVUTIL_VERSION_INT AV_VERSION_INT(AVCPP_AVUTIL_VERSION_MAJOR, \
3845
AVCPP_AVUTIL_VERSION_MINOR, \
3946
AVCPP_AVUTIL_VERSION_PATCH)
47+
#else
48+
#define AVCPP_HAS_AVUTIL 0
4049
#endif
4150

4251
#cmakedefine AVCPP_AVDEVICE_VERSION_MAJOR @AVCPP_AVDEVICE_VERSION_MAJOR@
4352
#cmakedefine AVCPP_AVDEVICE_VERSION_MINOR @AVCPP_AVDEVICE_VERSION_MINOR@
4453
#cmakedefine AVCPP_AVDEVICE_VERSION_PATCH @AVCPP_AVDEVICE_VERSION_PATCH@
4554
#cmakedefine AVCPP_AVDEVICE_VERSION_TWEAK @AVCPP_AVDEVICE_VERSION_TWEAK@
4655
#ifdef AVCPP_AVDEVICE_VERSION_MAJOR
56+
#define AVCPP_HAS_AVDEVICE 1
4757
#define AVCPP_AVDEVICE_VERSION_INT AV_VERSION_INT(AVCPP_AVDEVICE_VERSION_MAJOR, \
4858
AVCPP_AVDEVICE_VERSION_MINOR, \
4959
AVCPP_AVDEVICE_VERSION_PATCH)
60+
#else
61+
#define AVCPP_HAS_AVDEVICE 0
5062
#endif
5163

5264
#cmakedefine AVCPP_AVFILTER_VERSION_MAJOR @AVCPP_AVFILTER_VERSION_MAJOR@
5365
#cmakedefine AVCPP_AVFILTER_VERSION_MINOR @AVCPP_AVFILTER_VERSION_MINOR@
5466
#cmakedefine AVCPP_AVFILTER_VERSION_PATCH @AVCPP_AVFILTER_VERSION_PATCH@
5567
#cmakedefine AVCPP_AVFILTER_VERSION_TWEAK @AVCPP_AVFILTER_VERSION_TWEAK@
5668
#ifdef AVCPP_AVFILTER_VERSION_MAJOR
69+
#define AVCPP_HAS_AVFILTER 1
5770
#define AVCPP_AVFILTER_VERSION_INT AV_VERSION_INT(AVCPP_AVFILTER_VERSION_MAJOR, \
5871
AVCPP_AVFILTER_VERSION_MINOR, \
5972
AVCPP_AVFILTER_VERSION_PATCH)
73+
#else
74+
#define AVCPP_HAS_AVFILTER 0
6075
#endif
6176

6277
#cmakedefine AVCPP_SWSCALE_VERSION_MAJOR @AVCPP_SWSCALE_VERSION_MAJOR@
6378
#cmakedefine AVCPP_SWSCALE_VERSION_MINOR @AVCPP_SWSCALE_VERSION_MINOR@
6479
#cmakedefine AVCPP_SWSCALE_VERSION_PATCH @AVCPP_SWSCALE_VERSION_PATCH@
6580
#cmakedefine AVCPP_SWSCALE_VERSION_TWEAK @AVCPP_SWSCALE_VERSION_TWEAK@
6681
#ifdef AVCPP_AVSWSCALE_VERSION_MAJOR
82+
#define AVCPP_HAS_AVSWSCALE 1
6783
#define AVCPP_SWSCALE_VERSION_INT AV_VERSION_INT(AVCPP_SWSCALE_VERSION_MAJOR, \
6884
AVCPP_SWSCALE_VERSION_MINOR, \
6985
AVCPP_SWSCALE_VERSION_PATCH)
86+
#else
87+
#define AVCPP_HAS_AVSWSCALE 0
7088
#endif
7189

7290
#cmakedefine AVCPP_SWRESAMPLE_VERSION_MAJOR @AVCPP_SWRESAMPLE_VERSION_MAJOR@
7391
#cmakedefine AVCPP_SWRESAMPLE_VERSION_MINOR @AVCPP_SWRESAMPLE_VERSION_MINOR@
7492
#cmakedefine AVCPP_SWRESAMPLE_VERSION_PATCH @AVCPP_SWRESAMPLE_VERSION_PATCH@
7593
#cmakedefine AVCPP_SWRESAMPLE_VERSION_TWEAK @AVCPP_SWRESAMPLE_VERSION_TWEAK@
7694
#ifdef AVCPP_AVSWRESAMPLE_VERSION_MAJOR
95+
#define AVCPP_HAS_AVSWRESAMPLE 1
7796
#define AVCPP_AVSWRESAMPLE_VERSION_INT AV_VERSION_INT(AVCPP_SWRESAMPLE_VERSION_MAJOR, \
7897
AVCPP_SWRESAMPLE_VERSION_MINOR, \
7998
AVCPP_SWRESAMPLE_VERSION_PATCH)
99+
#else
100+
#define AVCPP_HAS_AVSWRESAMPLE 0
80101
#endif

0 commit comments

Comments
 (0)