Skip to content

Commit

Permalink
FFmpeg: Move av/swresample decision into CMake (#693)
Browse files Browse the repository at this point in the history
* FFmpeg: Move av/swresample decision into CMake

By making the determination as to which resampling library to use
in the `src/CMakeLists.txt` code, only that library needs to be
linked with libopenshot (and not the unused one), plus the choice
can be displayed in the FeatureSummary at configure time.

* src/CMakeLists: Fix FFmpeg hwaccel version check
  • Loading branch information
ferdnyc committed Jun 26, 2021
1 parent 27e8497 commit 68f03b5
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 253 deletions.
21 changes: 16 additions & 5 deletions src/CMakeLists.txt
Expand Up @@ -294,12 +294,17 @@ find_package(FFmpeg REQUIRED
)

set(all_comps avcodec avformat avutil swscale)
if(TARGET FFmpeg::swresample)
list(APPEND all_comps swresample)
set(version_comps avcodec avformat avutil)

# Pick a resampler. Prefer swresample if possible
if(TARGET FFmpeg::swresample AND ${FFmpeg_avformat_VERSION} VERSION_GREATER "57.0.0")
set(resample_lib swresample)
set(USE_SW TRUE)
else()
list(APPEND all_comps avresample)
set(resample_lib avresample)
set(USE_SW FALSE)
endif()
set(version_comps avcodec avformat avutil)
list(APPEND all_comps ${resample_lib})

foreach(ff_comp IN LISTS all_comps)
if(TARGET FFmpeg::${ff_comp})
Expand All @@ -313,9 +318,15 @@ foreach(ff_comp IN LISTS all_comps)
endif()
endforeach()

# Indicate which resampler we linked with, and set a config header flag
add_feature_info("FFmpeg ${resample_lib}" TRUE "Audio resampling uses ${resample_lib}")
# Set the appropriate flag in OpenShotVersion.h
set(FFMPEG_USE_SWRESAMPLE ${USE_SW} CACHE BOOL "libswresample used for audio resampling" FORCE)
mark_as_advanced(FFMPEG_USE_SWRESAMPLE)

# Version check for hardware-acceleration code
if(USE_HW_ACCEL AND FFmpeg_avcodec_VERSION)
if(${FFmpeg_avcodec_VERSION} VERSION_GREATER "57.107.100")
if(${FFmpeg_avcodec_VERSION} VERSION_GREATER "57.106")
set(HAVE_HW_ACCEL TRUE)
endif()
endif()
Expand Down

0 comments on commit 68f03b5

Please sign in to comment.