diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index 585feae2a..ed0c8feb2 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -16,9 +16,35 @@ find_package(Libavformat REQUIRED) include_directories(${LIBAVFORMAT_INCLUDE_DIRS}) add_definitions(${LIBAVFORMAT_DEFINITIONS}) -find_package(Libavcodec REQUIRED) -include_directories(${LIBAVCODEC_INCLUDE_DIRS}) -add_definitions(${LIBAVCODEC_DEFINITIONS}) +find_package(Libavcodec QUIET) +find_package(ImageMagick QUIET COMPONENTS MagickCore) + +if(NOT ImageMagick_MagickCore_FOUND AND NOT LIBAVCODEC_FOUND) + message(FATAL_ERROR "Either MagickCore or Libavcodec is required, but both were not found") +endif() + +option(LIBOBS_PREFER_IMAGEMAGICK "Prefer ImageMagick over ffmpeg for image loading" ON) + +if(NOT LIBAVCODEC_FOUND OR (ImageMagick_MagickCore_FOUND AND LIBOBS_PREFER_IMAGEMAGICK)) + message(STATUS "Using ImageMagick for image loading in libobs") + + set(libobs_image_loading_SOURCES + graphics/graphics-magick.c) + set(libobs_image_loading_LIBRARIES + ${ImageMagick_LIBRARIES}) + + include_directories( + ${ImageMagick_INCLUDE_DIRS}) +else() + message(STATUS "Using libavcodec for image loading in libobs") + + set(libobs_image_loading_SOURCES + graphics/graphics-ffmpeg.c) + set(libobs_image_loading_LIBRARIES + ${LIBAVCODEC_LIBRARIES}) + + include_directories(${LIBAVCODEC_INCLUDE_DIRS}) +endif() add_definitions(-DLIBOBS_EXPORTS) @@ -81,6 +107,7 @@ set(libobs_callback_HEADERS callback/signal.h) set(libobs_graphics_SOURCES + ${libobs_image_loading_SOURCES} graphics/quat.c graphics/effect-parser.c graphics/axisang.c @@ -92,7 +119,6 @@ set(libobs_graphics_SOURCES graphics/matrix4.c graphics/vec3.c graphics/graphics.c - graphics/graphics-ffmpeg.c graphics/shader-parser.c graphics/plane.c graphics/effect.c @@ -197,7 +223,8 @@ set(libobs_libobs_HEADERS obs-module.h obs-scene.h obs-source.h - obs-output.h) + obs-output.h + obs-ffmpeg-compat.h) set(libobs_SOURCES ${libobs_callback_SOURCES} @@ -240,11 +267,11 @@ target_link_libraries(libobs PRIVATE jansson ${libobs_PLATFORM_DEPS} + ${libobs_image_loading_LIBRARIES} ${LIBSWSCALE_LIBRARIES} ${LIBSWRESAMPLE_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} - ${LIBAVUTIL_LIBRARIES} - ${LIBAVCODEC_LIBRARIES}) + ${LIBAVUTIL_LIBRARIES}) install_obs_core(libobs EXPORT LibObs) install_obs_data(libobs ../build/data/libobs libobs) diff --git a/libobs/graphics/graphics-ffmpeg.c b/libobs/graphics/graphics-ffmpeg.c index 8de821371..4e3c2bb36 100644 --- a/libobs/graphics/graphics-ffmpeg.c +++ b/libobs/graphics/graphics-ffmpeg.c @@ -4,6 +4,8 @@ #include #include +#include "../obs-ffmpeg-compat.h" + struct ffmpeg_image { const char *file; AVFormatContext *fmt_ctx; @@ -121,7 +123,7 @@ static bool ffmpeg_image_decode(struct ffmpeg_image *info, uint8_t *out, { AVPacket packet = {0}; bool success = false; - AVFrame *frame = avcodec_alloc_frame(); + AVFrame *frame = av_frame_alloc(); int got_frame = 0; int ret; @@ -152,7 +154,7 @@ static bool ffmpeg_image_decode(struct ffmpeg_image *info, uint8_t *out, fail: av_free_packet(&packet); - avcodec_free_frame(&frame); + av_frame_free(&frame); return success; } diff --git a/libobs/graphics/graphics-magick.c b/libobs/graphics/graphics-magick.c index e32cd2e6d..e6d80f2e6 100644 --- a/libobs/graphics/graphics-magick.c +++ b/libobs/graphics/graphics-magick.c @@ -30,7 +30,7 @@ texture_t gs_create_texture_from_file(const char *file) data, exception); if (exception->severity == UndefinedException) tex = gs_create_texture(cx, cy, GS_BGRA, 1, - (const uint8**)&data, 0); + (const uint8_t**)&data, 0); else blog(LOG_WARNING, "magickcore warning/error getting " "pixels from file '%s': %s", file, diff --git a/libobs/obs-ffmpeg-compat.h b/libobs/obs-ffmpeg-compat.h new file mode 100644 index 000000000..922891781 --- /dev/null +++ b/libobs/obs-ffmpeg-compat.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +/* LIBAVCODEC_VERSION_CHECK checks for the right version of libav and FFmpeg + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBAVCODEC_VERSION_CHECK( a, b, c, d, e ) \ + ( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \ + (LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) ) ) + +#if !LIBAVCODEC_VERSION_CHECK(54, 28, 0, 59, 100) +# define avcodec_free_frame av_freep +#endif + +#if LIBAVCODEC_VERSION_INT < 0x371c01 +# define av_frame_alloc avcodec_alloc_frame +# define av_frame_unref avcodec_get_frame_defaults +# define av_frame_free avcodec_free_frame +#endif + diff --git a/plugins/obs-ffmpeg/CMakeLists.txt b/plugins/obs-ffmpeg/CMakeLists.txt index 9251be942..275c54965 100644 --- a/plugins/obs-ffmpeg/CMakeLists.txt +++ b/plugins/obs-ffmpeg/CMakeLists.txt @@ -26,7 +26,8 @@ include_directories(${LIBSWRESAMPLE_INCLUDE_DIRS}) add_definitions(${LIBSWRESAMPLE_DEFINITIONS}) set(obs-ffmpeg_HEADERS - obs-ffmpeg-formats.h) + obs-ffmpeg-formats.h + obs-ffmpeg-compat.h) set(obs-ffmpeg_SOURCES obs-ffmpeg.c obs-ffmpeg-aac.c