Skip to content

Commit 656ab19

Browse files
authored
Make avdevice library optional again (#1246)
* Make avdevice library optional again It is not used by avformat when performing playback via SDL2, the only thing it does is initializing avdevice and not using it later. * Add USE_AVDEVICE option This option is ON by default and will disable linking to avdevice when set to OFF. If the option is ON, but avdevice is not found, then the build will fail as per #1115
1 parent 55bd351 commit 656ab19

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ option(CLANG_FORMAT "Enable Clang Format" ON)
2020
option(BUILD_TESTS_WITH_QT6 "Build test against Qt 6" ON)
2121

2222
option(MOD_AVFORMAT "Enable avformat module" ON)
23+
option(USE_AVDEVICE "Integrate FFmpeg libavdevice for capture" ON)
2324
option(MOD_DECKLINK "Enable DeckLink module" ON)
2425
option(MOD_FREI0R "Enable Frei0r module" ON)
2526
option(MOD_GDK "Enable GDK module" ON)
@@ -227,14 +228,19 @@ if(MOD_GDK OR MOD_GTK)
227228
endif()
228229

229230
if(MOD_AVFORMAT)
231+
set(OPTIONAL_FFMPEG_COMPONENTS)
232+
if(USE_AVDEVICE)
233+
list(APPEND OPTIONAL_FFMPEG_COMPONENTS AVDEVICE)
234+
endif()
235+
230236
find_package(FFmpeg REQUIRED COMPONENTS
231237
AVFORMAT
232238
SWSCALE
233239
AVUTIL
234240
AVCODEC
235241
AVFILTER
236-
AVDEVICE
237242
SWRESAMPLE
243+
${OPTIONAL_FFMPEG_COMPONENTS}
238244
)
239245

240246
list(APPEND MLT_SUPPORTED_COMPONENTS avformat)

‎cmake/FindFFmpeg.cmake‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ foreach (_component ${FFmpeg_FIND_COMPONENTS})
194194
endif ()
195195
list(APPEND _FFmpeg_FOUND_LIBRARIES ${${_component}_LIBRARIES})
196196
endif ()
197-
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS ${_component}_FOUND)
197+
if (${FFMPEG_FIND_REQUIRED_${_component}})
198+
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS ${_component}_FOUND)
199+
endif()
198200
endforeach ()
199201
list(INSERT _FFmpeg_REQUIRED_VARS 0 _FFmpeg_FOUND_LIBRARIES)
200202

‎src/modules/avformat/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ if(WIN32)
5151
endif()
5252
endif()
5353

54+
if(USE_AVDEVICE AND AVDEVICE_FOUND)
55+
target_compile_definitions(mltavformat PRIVATE USE_AVDEVICE)
56+
endif()
57+
5458
if(CPU_MMX)
5559
target_compile_definitions(mltavformat PRIVATE USE_MMX)
5660
endif()

‎src/modules/avformat/factory.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ extern mlt_link link_swresample_init(mlt_profile profile, mlt_service_type, cons
4545
// ffmpeg Header files
4646
#include "mltavformat_export.h"
4747
#include <libavcodec/avcodec.h>
48+
#ifdef USE_AVDEVICE
4849
#include <libavdevice/avdevice.h>
50+
#endif
4951
#include <libavfilter/avfilter.h>
5052
#include <libavformat/avformat.h>
5153
#include <libavutil/opt.h>
@@ -58,7 +60,9 @@ static void avformat_init()
5860
// Initialise avformat if necessary
5961
if (avformat_initialised == 0) {
6062
avformat_initialised = 1;
63+
#ifdef USE_AVDEVICE
6164
avdevice_register_all();
65+
#endif
6266
avformat_network_init();
6367
av_log_set_level(mlt_log_get_level());
6468
if (getenv("MLT_AVFORMAT_PRODUCER_CACHE")) {

0 commit comments

Comments
 (0)