commit
df47f31e83
|
@ -5,3 +5,6 @@
|
|||
*.vcxproj text eol=crlf
|
||||
*.vcxproj text eol=crlf
|
||||
*.vcxproj.filters text eol=crlf
|
||||
|
||||
cmake/ALL_BUILD.vcxproj.user.in text eol=crlf
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# Libavcodec_FOUND
|
||||
# Libavcodec_INCLUDE_DIR
|
||||
# Libavcodec_LIBRARIES
|
||||
# LIBAVCODEC_FOUND
|
||||
# LIBAVCODEC_INCLUDE_DIRS
|
||||
# LIBAVCODEC_LIBRARIES
|
||||
#
|
||||
|
||||
if(Libavcodec_INCLUDE_DIR AND Libavcodec_LIBRARIES)
|
||||
set(Libavcodec_FOUND TRUE)
|
||||
if(LIBAVCODEC_INCLUDE_DIRS AND LIBAVCODEC_LIBRARIES)
|
||||
set(LIBAVCODEC_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
|
@ -31,8 +31,8 @@ else()
|
|||
NAMES avcodec
|
||||
HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_AVCODEC_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(Libavcodec_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavcodec include dir")
|
||||
set(Libavcodec_LIBRARIES ${AVCODEC_LIB} CACHE STRING "Libavcodec libraries")
|
||||
set(LIBAVCODEC_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavcodec include dir")
|
||||
set(LIBAVCODEC_LIBRARIES ${AVCODEC_LIB} CACHE STRING "Libavcodec libraries")
|
||||
|
||||
find_package_handle_standard_args(Libavcodec DEFAULT_MSG AVCODEC_LIB FFMPEG_INCLUDE_DIR)
|
||||
mark_as_advanced(FFMPEG_INCLUDE_DIR AVCODEC_LIB)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# Libavformat_FOUND
|
||||
# Libavformat_INCLUDE_DIR
|
||||
# Libavformat_LIBRARIES
|
||||
# LIBAVFORMAT_FOUND
|
||||
# LIBAVFORMAT_INCLUDE_DIRS
|
||||
# LIBAVFORMAT_LIBRARIES
|
||||
#
|
||||
|
||||
if(Libavformat_INCLUDE_DIR AND Libavformat_LIBRARIES)
|
||||
set(Libavformat_FOUND TRUE)
|
||||
if(LIBAVFORMAT_INCLUDE_DIRS AND LIBAVFORMAT_LIBRARIES)
|
||||
set(LIBAVFORMAT_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
|
@ -31,8 +31,8 @@ else()
|
|||
NAMES avformat
|
||||
HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_AVFORMAT_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(Libavformat_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavformat include dir")
|
||||
set(Libavformat_LIBRARIES ${AVFORMAT_LIB} CACHE STRING "Libavformat libraries")
|
||||
set(LIBAVFORMAT_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavformat include dir")
|
||||
set(LIBAVFORMAT_LIBRARIES ${AVFORMAT_LIB} CACHE STRING "Libavformat libraries")
|
||||
|
||||
find_package_handle_standard_args(Libavformat DEFAULT_MSG AVFORMAT_LIB FFMPEG_INCLUDE_DIR)
|
||||
mark_as_advanced(FFMPEG_INCLUDE_DIR AVFORMAT_LIB)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# Libavutil_FOUND
|
||||
# Libavutil_INCLUDE_DIR
|
||||
# Libavutil_LIBRARIES
|
||||
# LIBAVUTIL_FOUND
|
||||
# LIBAVUTIL_INCLUDE_DIRS
|
||||
# LIBAVUTIL_LIBRARIES
|
||||
#
|
||||
|
||||
if(Libavutil_INCLUDE_DIR AND Libavutil_LIBRARIES)
|
||||
set(Libavutil_FOUND TRUE)
|
||||
if(LIBAVUTIL_INCLUDE_DIRS AND LIBAVUTIL_LIBRARIES)
|
||||
set(LIBAVUTIL_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
|
@ -31,8 +31,8 @@ else()
|
|||
NAMES avutil
|
||||
HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_AVUTIL_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(Libavutil_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavutil include dir")
|
||||
set(Libavutil_LIBRARIES ${AVUTIL_LIB} CACHE STRING "Libavutil libraries")
|
||||
set(LIBAVUTIL_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavutil include dir")
|
||||
set(LIBAVUTIL_LIBRARIES ${AVUTIL_LIB} CACHE STRING "Libavutil libraries")
|
||||
|
||||
find_package_handle_standard_args(Libavutil DEFAULT_MSG AVUTIL_LIB FFMPEG_INCLUDE_DIR)
|
||||
mark_as_advanced(FFMPEG_INCLUDE_DIR AVUTIL_LIB)
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# LIBFDK_FOUND
|
||||
# LIBFDK_INCLUDE_DIRS
|
||||
# LIBFDK_LIBRARIES
|
||||
#
|
||||
|
||||
if(LIBFDK_INCLUDE_DIRS AND LIBFDK_LIBRARIES)
|
||||
set(LIBFDK_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(_LIBFDK QUIET fdk-aac)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(_lib_suffix 64)
|
||||
else()
|
||||
set(_lib_suffix 32)
|
||||
endif()
|
||||
|
||||
find_path(Libfdk_INCLUDE_DIR
|
||||
NAMES fdk-aac/aacenc_lib.h
|
||||
HINTS
|
||||
ENV LibfdkPath
|
||||
ENV FFmpegPath
|
||||
${_LIBFDK_INCLUDE_DIRS}
|
||||
/usr/include /usr/local/include /opt/local/include /sw/include)
|
||||
|
||||
find_library(Libfdk_LIB
|
||||
NAMES libfdk-aac
|
||||
HINTS
|
||||
${Libfdk_INCLUDE_DIR}/../lib
|
||||
${Libfdk_INCLUDE_DIR}/lib${_lib_suffix}
|
||||
${_LIBFDK_LIBRARY_DIRS}
|
||||
/usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(LIBFDK_INCLUDE_DIRS ${Libfdk_INCLUDE_DIR} CACHE PATH "Libfdk include dir")
|
||||
set(LIBFDK_LIBRARIES ${Libfdk_LIB} CACHE STRING "Libfdk libraries")
|
||||
|
||||
find_package_handle_standard_args(Libfdk DEFAULT_MSG Libfdk_LIB Libfdk_INCLUDE_DIR)
|
||||
mark_as_advanced(Libfdk_INCLUDE_DIR Libfdk_LIB)
|
||||
endif()
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# Libswresample_FOUND
|
||||
# Libswresample_INCLUDE_DIR
|
||||
# Libswresample_LIBRARIES
|
||||
# LIBSWRESAMPLE_FOUND
|
||||
# LIBSWRESAMPLE_INCLUDE_DIRS
|
||||
# LIBSWRESAMPLE_LIBRARIES
|
||||
#
|
||||
|
||||
if(Libswresample_INCLUDE_DIR AND Libswresample_LIBRARIES)
|
||||
set(Libswresample_FOUND TRUE)
|
||||
if(LIBSWRESAMPLE_INCLUDE_DIRS AND LIBSWRESAMPLE_LIBRARIES)
|
||||
set(LIBSWRESAMPLE_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
|
@ -31,8 +31,8 @@ else()
|
|||
NAMES swresample
|
||||
HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_SWRESAMPLE_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(Libswresample_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libswresample include dir")
|
||||
set(Libswresample_LIBRARIES ${SWRESAMPLE_LIB} CACHE STRING "Libswresample libraries")
|
||||
set(LIBSWRESAMPLE_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libswresample include dir")
|
||||
set(LIBSWRESAMPLE_LIBRARIES ${SWRESAMPLE_LIB} CACHE STRING "Libswresample libraries")
|
||||
|
||||
find_package_handle_standard_args(Libswresample DEFAULT_MSG SWRESAMPLE_LIB FFMPEG_INCLUDE_DIR)
|
||||
mark_as_advanced(FFMPEG_INCLUDE_DIR SWRESAMPLE_LIB)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# Libswscale_FOUND
|
||||
# Libswscale_INCLUDE_DIR
|
||||
# Libswscale_LIBRARIES
|
||||
# LIBSWSCALE_FOUND
|
||||
# LIBSWSCALE_INCLUDE_DIRS
|
||||
# LIBSWSCALE_LIBRARIES
|
||||
#
|
||||
|
||||
if(Libswscale_INCLUDE_DIR AND Libswscale_LIBRARIES)
|
||||
set(Libswscale_FOUND TRUE)
|
||||
if(LIBSWSCALE_INCLUDE_DIRS AND LIBSWSCALE_LIBRARIES)
|
||||
set(LIBSWSCALE_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
|
@ -31,8 +31,8 @@ else()
|
|||
NAMES swscale
|
||||
HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_SWSCALE_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(Libswscale_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libswscale include dir")
|
||||
set(Libswscale_LIBRARIES ${SWSCALE_LIB} CACHE STRING "Libswscale libraries")
|
||||
set(LIBSWSCALE_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libswscale include dir")
|
||||
set(LIBSWSCALE_LIBRARIES ${SWSCALE_LIB} CACHE STRING "Libswscale libraries")
|
||||
|
||||
find_package_handle_standard_args(Libswscale DEFAULT_MSG SWSCALE_LIB FFMPEG_INCLUDE_DIR)
|
||||
mark_as_advanced(FFMPEG_INCLUDE_DIR SWSCALE_LIB)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Once done these will be defined:
|
||||
#
|
||||
# Libx264_FOUND
|
||||
# Libx264_INCLUDE_DIR
|
||||
# Libx264_LIBRARIES
|
||||
# LIBX264_FOUND
|
||||
# LIBX264_INCLUDE_DIRS
|
||||
# LIBX264_LIBRARIES
|
||||
#
|
||||
|
||||
if(Libx264_INCLUDE_DIR AND Libx264_LIBRARIES)
|
||||
set(Libx264_FOUND TRUE)
|
||||
if(LIBX264_INCLUDE_DIRS AND LIBX264_LIBRARIES)
|
||||
set(LIBX264_FOUND TRUE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
|
@ -23,6 +23,7 @@ else()
|
|||
NAMES x264.h
|
||||
HINTS
|
||||
ENV x264Path
|
||||
ENV FFmpegPath
|
||||
${_X264_INCLUDE_DIRS}
|
||||
/usr/include /usr/local/include /opt/local/include /sw/include)
|
||||
|
||||
|
@ -30,8 +31,8 @@ else()
|
|||
NAMES x264 libx264
|
||||
HINTS ${X264_INCLUDE_DIR}/../lib ${X264_INCLUDE_DIR}/lib${_lib_suffix} ${_X264_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
|
||||
|
||||
set(Libx264_INCLUDE_DIR ${X264_INCLUDE_DIR} CACHE PATH "x264 include dir")
|
||||
set(Libx264_LIBRARIES ${X264_LIB} CACHE STRING "x264 libraries")
|
||||
set(LIBX264_INCLUDE_DIRS ${X264_INCLUDE_DIR} CACHE PATH "x264 include dir")
|
||||
set(LIBX264_LIBRARIES ${X264_LIB} CACHE STRING "x264 libraries")
|
||||
|
||||
find_package_handle_standard_args(Libx264 DEFAULT_MSG X264_LIB X264_INCLUDE_DIR)
|
||||
mark_as_advanced(X264_INCLUDE_DIR X264_LIB)
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
project(libobs)
|
||||
|
||||
find_package(Libswscale REQUIRED)
|
||||
include_directories(${Libswscale_INCLUDE_DIR})
|
||||
add_definitions(${Libswscale_DEFINITIONS})
|
||||
include_directories(${LIBSWSCALE_INCLUDE_DIRS})
|
||||
add_definitions(${LIBSWSCALE_DEFINITIONS})
|
||||
|
||||
find_package(Libswresample REQUIRED)
|
||||
include_directories(${Libswresample_INCLUDE_DIR})
|
||||
add_definitions(${Libswresample_DEFINITIONS})
|
||||
include_directories(${LIBSWRESAMPLE_INCLUDE_DIRS})
|
||||
add_definitions(${LIBSWRESAMPLE_DEFINITIONS})
|
||||
|
||||
find_package(Libavutil REQUIRED)
|
||||
include_directories(${Libavutil_INCLUDE_DIR})
|
||||
add_definitions(${Libavutil_DEFINITIONS})
|
||||
include_directories(${LIBAVUTIL_INCLUDE_DIRS})
|
||||
add_definitions(${LIBAVUTIL_DEFINITIONS})
|
||||
|
||||
find_package(Libavformat REQUIRED)
|
||||
include_directories(${Libavformat_INCLUDE_DIR})
|
||||
add_definitions(${Libavformat_DEFINITIONS})
|
||||
include_directories(${LIBAVFORMAT_INCLUDE_DIRS})
|
||||
add_definitions(${LIBAVFORMAT_DEFINITIONS})
|
||||
|
||||
add_definitions(-DLIBOBS_EXPORTS)
|
||||
|
||||
|
@ -235,11 +235,11 @@ target_link_libraries(libobs
|
|||
PRIVATE
|
||||
jansson
|
||||
${libobs_PLATFORM_DEPS}
|
||||
${Libswscale_LIBRARIES}
|
||||
${Libswresample_LIBRARIES}
|
||||
${Libavutil_LIBRARIES})
|
||||
${LIBSWSCALE_LIBRARIES}
|
||||
${LIBSWRESAMPLE_LIBRARIES}
|
||||
${LIBAVFORMAT_LIBRARIES}
|
||||
${LIBAVUTIL_LIBRARIES})
|
||||
|
||||
install_obs_core(libobs EXPORT LibObs)
|
||||
install_obs_data(libobs ../build/data/libobs libobs)
|
||||
install_obs_headers(${libobs_HEADERS})
|
||||
|
||||
|
|
|
@ -328,14 +328,18 @@ bool OBSBasic::InitOutputs()
|
|||
|
||||
bool OBSBasic::InitEncoders()
|
||||
{
|
||||
aac = obs_audio_encoder_create("ffmpeg_aac", "aac", nullptr);
|
||||
if (!aac)
|
||||
return false;
|
||||
|
||||
x264 = obs_video_encoder_create("obs_x264", "h264", nullptr);
|
||||
if (!x264)
|
||||
return false;
|
||||
|
||||
aac = obs_audio_encoder_create("libfdk_aac", "aac", nullptr);
|
||||
|
||||
if(!aac)
|
||||
aac = obs_audio_encoder_create("ffmpeg_aac", "aac", nullptr);
|
||||
|
||||
if (!aac)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -463,6 +467,7 @@ void OBSBasic::OBSInit()
|
|||
* automatically later */
|
||||
obs_load_module("test-input");
|
||||
obs_load_module("obs-ffmpeg");
|
||||
obs_load_module("obs-libfdk");
|
||||
obs_load_module("obs-x264");
|
||||
obs_load_module("obs-outputs");
|
||||
obs_load_module("rtmp-services");
|
||||
|
|
|
@ -14,6 +14,7 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
|||
endif()
|
||||
|
||||
add_subdirectory(obs-x264)
|
||||
add_subdirectory(obs-libfdk)
|
||||
add_subdirectory(obs-ffmpeg)
|
||||
add_subdirectory(obs-outputs)
|
||||
add_subdirectory(rtmp-services)
|
||||
|
|
|
@ -6,24 +6,24 @@ if(WIN32)
|
|||
endif()
|
||||
|
||||
find_package(Libavcodec REQUIRED)
|
||||
include_directories(${Libavcodec_INCLUDE_DIR})
|
||||
add_definitions(${Libavcodec_DEFINITIONS})
|
||||
include_directories(${LIBAVCODEC_INCLUDE_DIRS})
|
||||
add_definitions(${LIBAVCODEC_DEFINITIONS})
|
||||
|
||||
find_package(Libavutil REQUIRED)
|
||||
include_directories(${Libavutil_INCLUDE_DIR})
|
||||
add_definitions(${Libavutil_DEFINITIONS})
|
||||
include_directories(${LIBAVUTIL_INCLUDE_DIRS})
|
||||
add_definitions(${LIBAVUTIL_DEFINITIONS})
|
||||
|
||||
find_package(Libswscale REQUIRED)
|
||||
include_directories(${Libswscale_INCLUDE_DIR})
|
||||
add_definitions(${Libswscale_DEFINITIONS})
|
||||
include_directories(${LIBSWSCALE_INCLUDE_DIRS})
|
||||
add_definitions(${LIBSWSCALE_DEFINITIONS})
|
||||
|
||||
find_package(Libavformat REQUIRED)
|
||||
include_directories(${Libavformat_INCLUDE_DIR})
|
||||
add_definitions(${Libavformat_DEFINITIONS})
|
||||
include_directories(${LIBAVFORMAT_INCLUDE_DIRS})
|
||||
add_definitions(${LIBAVFORMAT_DEFINITIONS})
|
||||
|
||||
find_package(Libswresample REQUIRED)
|
||||
include_directories(${Libswresample_INCLUDE_DIR})
|
||||
add_definitions(${Libswresample_DEFINITIONS})
|
||||
include_directories(${LIBSWRESAMPLE_INCLUDE_DIRS})
|
||||
add_definitions(${LIBSWRESAMPLE_DEFINITIONS})
|
||||
|
||||
set(obs-ffmpeg_HEADERS
|
||||
obs-ffmpeg-formats.h)
|
||||
|
@ -38,11 +38,11 @@ add_library(obs-ffmpeg MODULE
|
|||
target_link_libraries(obs-ffmpeg
|
||||
libobs
|
||||
${obs-ffmpeg_PLATFORM_DEPS}
|
||||
${Libavcodec_LIBRARIES}
|
||||
${Libavutil_LIBRARIES}
|
||||
${Libswscale_LIBRARIES}
|
||||
${Libavformat_LIBRARIES}
|
||||
${Libswresample_LIBRARIES})
|
||||
${LIBAVCODEC_LIBRARIES}
|
||||
${LIBAVUTIL_LIBRARIES}
|
||||
${LIBSWSCALE_LIBRARIES}
|
||||
${LIBAVFORMAT_LIBRARIES}
|
||||
${LIBSWRESAMPLE_LIBRARIES})
|
||||
|
||||
install_obs_plugin(obs-ffmpeg)
|
||||
|
||||
|
|
|
@ -143,6 +143,8 @@ static void *aac_create(obs_data_t settings, obs_encoder_t encoder)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
blog(LOG_INFO, "Using ffmpeg \"%s\" aac encoder", enc->aac->name);
|
||||
|
||||
enc->context = avcodec_alloc_context3(enc->aac);
|
||||
if (!enc->context) {
|
||||
aac_warn("aac_create", "Failed to create codec context");
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
project(obs-libfdk)
|
||||
|
||||
find_package(Libfdk QUIET)
|
||||
if(NOT LIBFDK_FOUND)
|
||||
message(STATUS "Libfdk not found - obs-libfdk plugin disabled")
|
||||
return()
|
||||
endif()
|
||||
|
||||
include_directories(${LIBFDK_INCLUDE_DIRS})
|
||||
add_definitions(${LIBFDK_DEFINITIONS})
|
||||
|
||||
set(obs-libfdk_SOURCES
|
||||
obs-libfdk.c)
|
||||
|
||||
add_library(obs-libfdk MODULE
|
||||
${obs-libfdk_SOURCES})
|
||||
target_link_libraries(obs-libfdk
|
||||
libobs
|
||||
${LIBFDK_LIBRARIES})
|
||||
|
||||
install_obs_plugin(obs-libfdk)
|
|
@ -0,0 +1,311 @@
|
|||
#include <obs-module.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
# ifndef _DEBUG
|
||||
# define _DEBUG
|
||||
# endif
|
||||
# undef DEBUG
|
||||
#endif
|
||||
|
||||
#include <fdk-aac/aacenc_lib.h>
|
||||
|
||||
|
||||
static const char *libfdk_get_error(AACENC_ERROR err)
|
||||
{
|
||||
switch(err) {
|
||||
case AACENC_OK:
|
||||
return "No error";
|
||||
case AACENC_INVALID_HANDLE:
|
||||
return "Invalid handle";
|
||||
case AACENC_MEMORY_ERROR:
|
||||
return "Memory allocation error";
|
||||
case AACENC_UNSUPPORTED_PARAMETER:
|
||||
return "Unsupported parameter";
|
||||
case AACENC_INVALID_CONFIG:
|
||||
return "Invalid config";
|
||||
case AACENC_INIT_ERROR:
|
||||
return "Initialization error";
|
||||
case AACENC_INIT_AAC_ERROR:
|
||||
return "AAC library initialization error";
|
||||
case AACENC_INIT_SBR_ERROR:
|
||||
return "SBR library initialization error";
|
||||
case AACENC_INIT_TP_ERROR:
|
||||
return "Transport library initialization error";
|
||||
case AACENC_INIT_META_ERROR:
|
||||
return "Metadata library initialization error";
|
||||
case AACENC_ENCODE_ERROR:
|
||||
return "Encoding error";
|
||||
case AACENC_ENCODE_EOF:
|
||||
return "End of file";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct libfdk_encoder {
|
||||
obs_encoder_t encoder;
|
||||
|
||||
int channels, sample_rate;
|
||||
|
||||
HANDLE_AACENCODER fdkhandle;
|
||||
AACENC_InfoStruct info;
|
||||
|
||||
uint64_t total_samples;
|
||||
|
||||
int frame_size_bytes;
|
||||
|
||||
uint8_t *packet_buffer;
|
||||
int packet_buffer_size;
|
||||
} libfdk_encoder_t;
|
||||
|
||||
static const char *libfdk_getname(const char *locale)
|
||||
{
|
||||
UNUSED_PARAMETER(locale);
|
||||
return "libfdk aac encoder";
|
||||
}
|
||||
|
||||
static obs_properties_t libfdk_properties(const char *locale)
|
||||
{
|
||||
obs_properties_t props = obs_properties_create(locale);
|
||||
|
||||
obs_properties_add_int(props, "bitrate", "Bitrate", 32, 256, 32);
|
||||
obs_properties_add_bool(props, "afterburner", "Enable AAC Afterburner");
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
static void libfdk_defaults(obs_data_t settings)
|
||||
{
|
||||
obs_data_set_default_int(settings, "bitrate", 128);
|
||||
obs_data_set_default_bool(settings, "afterburner", true);
|
||||
}
|
||||
|
||||
#define CHECK_LIBFDK(r) \
|
||||
if((err = (r)) != AACENC_OK) { \
|
||||
blog(LOG_ERROR, #r " failed: %s", libfdk_get_error(err)); \
|
||||
goto fail; \
|
||||
}
|
||||
|
||||
static void *libfdk_create(obs_data_t settings, obs_encoder_t encoder)
|
||||
{
|
||||
bool hasFdkHandle = false;
|
||||
libfdk_encoder_t *enc = 0;
|
||||
int bitrate = (int)obs_data_getint(settings, "bitrate") * 1000;
|
||||
int afterburner = obs_data_getbool(settings, "afterburner") ? 1 : 0;
|
||||
audio_t audio = obs_encoder_audio(encoder);
|
||||
int mode = 0;
|
||||
AACENC_ERROR err;
|
||||
|
||||
if (!bitrate) {
|
||||
blog(LOG_ERROR, "Invalid bitrate");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enc = bzalloc(sizeof(libfdk_encoder_t));
|
||||
enc->encoder = encoder;
|
||||
|
||||
enc->channels = (int)audio_output_channels(audio);
|
||||
enc->sample_rate = audio_output_samplerate(audio);
|
||||
|
||||
switch(enc->channels) {
|
||||
case 1:
|
||||
mode = MODE_1;
|
||||
break;
|
||||
case 2:
|
||||
mode = MODE_2;
|
||||
break;
|
||||
case 3:
|
||||
mode = MODE_1_2;
|
||||
break;
|
||||
case 4:
|
||||
mode = MODE_1_2_1;
|
||||
break;
|
||||
case 5:
|
||||
mode = MODE_1_2_2;
|
||||
break;
|
||||
case 6:
|
||||
mode = MODE_1_2_2_1;
|
||||
break;
|
||||
default:
|
||||
blog(LOG_ERROR, "Invalid channel count");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
CHECK_LIBFDK(aacEncOpen(&enc->fdkhandle, 0, enc->channels));
|
||||
hasFdkHandle = true;
|
||||
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_AOT,
|
||||
2)); // MPEG-4 AAC-LC
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_SAMPLERATE,
|
||||
enc->sample_rate));
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_CHANNELMODE, mode));
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_CHANNELORDER, 1));
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_BITRATEMODE, 0));
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_BITRATE, bitrate));
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_TRANSMUX, 0));
|
||||
CHECK_LIBFDK(aacEncoder_SetParam(enc->fdkhandle, AACENC_AFTERBURNER,
|
||||
afterburner));
|
||||
|
||||
CHECK_LIBFDK(aacEncEncode(enc->fdkhandle, NULL, NULL, NULL, NULL));
|
||||
|
||||
CHECK_LIBFDK(aacEncInfo(enc->fdkhandle, &enc->info));
|
||||
|
||||
enc->frame_size_bytes = enc->info.frameLength * 2 * enc->channels;
|
||||
|
||||
enc->packet_buffer_size = enc->channels * 768;
|
||||
if(enc->packet_buffer_size < 8192)
|
||||
enc->packet_buffer_size = 8192;
|
||||
|
||||
enc->packet_buffer = bmalloc(enc->packet_buffer_size);
|
||||
|
||||
blog(LOG_INFO, "libfdk_aac encoder created");
|
||||
|
||||
return enc;
|
||||
|
||||
fail:
|
||||
|
||||
if(hasFdkHandle)
|
||||
aacEncClose(&enc->fdkhandle);
|
||||
|
||||
if(enc->packet_buffer)
|
||||
bfree(enc->packet_buffer);
|
||||
|
||||
if(enc)
|
||||
bfree(enc);
|
||||
|
||||
blog(LOG_WARNING, "libfdk_aac encoder creation failed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void libfdk_destroy(void *data)
|
||||
{
|
||||
libfdk_encoder_t *enc = data;
|
||||
|
||||
aacEncClose(&enc->fdkhandle);
|
||||
|
||||
bfree(enc->packet_buffer);
|
||||
bfree(enc);
|
||||
|
||||
blog(LOG_INFO, "libfdk_aac encoder destroyed");
|
||||
}
|
||||
|
||||
static bool libfdk_encode(void *data, struct encoder_frame *frame,
|
||||
struct encoder_packet *packet, bool *received_packet)
|
||||
{
|
||||
libfdk_encoder_t *enc = data;
|
||||
|
||||
AACENC_BufDesc in_buf = { 0 };
|
||||
AACENC_BufDesc out_buf = { 0 };
|
||||
AACENC_InArgs in_args = { 0 };
|
||||
AACENC_OutArgs out_args = { 0 };
|
||||
int in_identifier = IN_AUDIO_DATA;
|
||||
int in_size, in_elem_size;
|
||||
int out_identifier = OUT_BITSTREAM_DATA;
|
||||
int out_size, out_elem_size;
|
||||
void *in_ptr;
|
||||
void *out_ptr;
|
||||
AACENC_ERROR err;
|
||||
|
||||
|
||||
in_ptr = frame->data[0];
|
||||
in_size = enc->frame_size_bytes;
|
||||
in_elem_size = 2;
|
||||
|
||||
in_args.numInSamples = enc->info.frameLength * enc->channels;
|
||||
in_buf.numBufs = 1;
|
||||
in_buf.bufs = &in_ptr;
|
||||
in_buf.bufferIdentifiers = &in_identifier;
|
||||
in_buf.bufSizes = &in_size;
|
||||
in_buf.bufElSizes = &in_elem_size;
|
||||
|
||||
out_ptr = enc->packet_buffer;
|
||||
out_size = enc->packet_buffer_size;
|
||||
out_elem_size = 1;
|
||||
|
||||
out_buf.numBufs = 1;
|
||||
out_buf.bufs = &out_ptr;
|
||||
out_buf.bufferIdentifiers = &out_identifier;
|
||||
out_buf.bufSizes = &out_size;
|
||||
out_buf.bufElSizes = &out_elem_size;
|
||||
|
||||
if((err = aacEncEncode(enc->fdkhandle, &in_buf, &out_buf, &in_args,
|
||||
&out_args)) != AACENC_OK) {
|
||||
blog(LOG_ERROR, "Failed to encode frame: %s", libfdk_get_error(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
enc->total_samples += enc->info.frameLength;
|
||||
|
||||
if(out_args.numOutBytes == 0) {
|
||||
*received_packet = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
*received_packet = true;
|
||||
|
||||
packet->pts = enc->total_samples -
|
||||
enc->info.encoderDelay; // TODO: Just a guess, find out if that's actualy right
|
||||
packet->dts = enc->total_samples - enc->info.encoderDelay;
|
||||
packet->data = enc->packet_buffer;
|
||||
packet->size = out_args.numOutBytes;
|
||||
packet->type = OBS_ENCODER_AUDIO;
|
||||
packet->timebase_num = 1;
|
||||
packet->timebase_den = enc->sample_rate;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libfdk_extra_data(void *data, uint8_t **extra_data, size_t *size)
|
||||
{
|
||||
libfdk_encoder_t *enc = data;
|
||||
|
||||
*size = enc->info.confSize;
|
||||
*extra_data = enc->info.confBuf;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libfdk_audio_info(void *data, struct audio_convert_info *info)
|
||||
{
|
||||
UNUSED_PARAMETER(data);
|
||||
|
||||
memset(info, 0, sizeof(struct audio_convert_info));
|
||||
info->format = AUDIO_FORMAT_16BIT;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t libfdk_frame_size(void *data)
|
||||
{
|
||||
libfdk_encoder_t *enc = data;
|
||||
|
||||
return enc->info.frameLength;
|
||||
}
|
||||
|
||||
struct obs_encoder_info obs_libfdk_encoder = {
|
||||
.id = "libfdk_aac",
|
||||
.type = OBS_ENCODER_AUDIO,
|
||||
.codec = "AAC",
|
||||
.getname = libfdk_getname,
|
||||
.create = libfdk_create,
|
||||
.destroy = libfdk_destroy,
|
||||
.encode = libfdk_encode,
|
||||
.frame_size = libfdk_frame_size,
|
||||
.defaults = libfdk_defaults,
|
||||
.properties = libfdk_properties,
|
||||
.extra_data = libfdk_extra_data,
|
||||
.audio_info = libfdk_audio_info
|
||||
};
|
||||
|
||||
bool obs_module_load(uint32_t libobs_ver)
|
||||
{
|
||||
UNUSED_PARAMETER(libobs_ver);
|
||||
|
||||
obs_register_encoder(&obs_libfdk_encoder);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
OBS_DECLARE_MODULE()
|
|
@ -1,8 +1,8 @@
|
|||
project(obs-x264)
|
||||
|
||||
find_package(Libx264 REQUIRED)
|
||||
include_directories(${Libx264_INCLUDE_DIR})
|
||||
add_definitions(${Libx264_DEFINITIONS})
|
||||
include_directories(${LIBX264_INCLUDE_DIRS})
|
||||
add_definitions(${LIBX264_DEFINITIONS})
|
||||
|
||||
set(obs-x264_SOURCES
|
||||
obs-x264.c
|
||||
|
@ -12,7 +12,7 @@ add_library(obs-x264 MODULE
|
|||
${obs-x264_SOURCES})
|
||||
target_link_libraries(obs-x264
|
||||
libobs
|
||||
${Libx264_LIBRARIES})
|
||||
${LIBX264_LIBRARIES})
|
||||
|
||||
install_obs_plugin(obs-x264)
|
||||
|
||||
|
|
Loading…
Reference in New Issue