Я пытаюсь скомпилировать ffmpeg с поддержкой h264 как внешний проект cmake. Но после компиляции я получаю ошибки ссылки на libavcodec.
Проблема компиляции происходит на компьютере с Ubuntu 18.04. Я установил все зависимости для ffmpeg, а также libx264-dev.
Cmake внешний проект
set( proj ffmpeg )
set( SHARED_FFMPEG )
set(BASIC
--extra-ldflags=-L/usr/local/lib
--extra-cflags=-I/usr/local/include
--enable-gpl
--enable-libx264)
option( FFMPEG_GPL "Use a GPL version of FFMPEG" OFF )
set(FFMPEG_INSTALL_DIR ${CMAKE_BINARY_DIR}/INSTALL )
ExternalProject_Add(${proj}
# Set up dirs
SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
INSTALL_DIR ${FFMPEG_INSTALL_DIR}
# get the project
GIT_REPOSITORY "https://github.com/FFmpeg/FFmpeg.git"
GIT_TAG "n3.2.13"
# Build the project
BUILD_IN_SOURCE 1
# Configure step
# DO STH FOR THE ARCHITECTURE...
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${FFMPEG_INSTALL_DIR} ${SHARED_FFMPEG} ${FFMPEG_GPL_FLAG} ${BASIC}
# BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j${NProcessors}
)
# define the library suffix
if( SUPER_SHARED_LIBS )
if( APPLE )
set(LIBRARY_SUFFIX .dylib)
else( APPLE )
set(LIBRARY_SUFFIX .so)
endif( APPLE )
else( SUPER_SHARED_LIBS )
set(LIBRARY_SUFFIX .a)
endif( SUPER_SHARED_LIBS )
# ADD DIRECTORIES FOR DEPENDENCIES IN Main/CMakeLists.txt
set( FFMPEG_LIBRARYS libavcodec.a
libavformat.a
libavutil.a
libswscale.a
)
include_directories(${FFMPEG_INSTALL_DIR}/include)
set(FFMPEG_LIBRARY_DIRS ${FFMPEG_INSTALL_DIR}/lib/)
link_directories(${FFMPEG_LIBRARY_DIRS})
C ++ Где я использовал библиотеку
extern "C" {
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/mathematics.h"
#include "libswscale/swscale.h"
#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096
}
...
fReceiveBuffer = new u_int8_t[DUMMY_SINK_RECEIVE_BUFFER_SIZE];
fReceiveBufferAV = new u_int8_t[DUMMY_SINK_RECEIVE_BUFFER_SIZE+4];
fReceiveBufferAV[0] = 0;
fReceiveBufferAV[1] = 0;
fReceiveBufferAV[2] = 0;
fReceiveBufferAV[3] = 1;
av_init_packet(&avpkt);
avpkt.flags |= AV_PKT_FLAG_KEY;
avpkt.pts = avpkt.dts = 0;
av_init_packet(&avpkt);
avpkt.flags |= AV_PKT_FLAG_KEY;
avpkt.pts = avpkt.dts = 0;
/* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
//codec = avcodec_find_decoder(CODEC_ID_MPEG1VIDEO);
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
...
Ошибка:
[100%] Linking CXX executable ../../bin/awesom-o
/home/tiburcio/CLionProjects/awesom-o/cmake-build-debug/INSTALL/lib/libavcodec.a(libx264.o): In function `X264_frame':
/home/tiburcio/CLionProjects/awesom-o/cmake-build-debug/ffmpeg/libavcodec/libx264.c:280: undefined reference to `x264_picture_init'
/home/tiburcio/CLionProjects/awesom-o/cmake-build-debug/INSTALL/lib/libavcodec.a(libx264.o): In function `reconfig_encoder':
/home/tiburcio/CLionProjects/awesom-o/cmake-build-debug/ffmpeg/libavcodec/libx264.c:266: undefined reference to `x264_encoder_reconfig'
/home/tiburcio/CLionProjects/awesom-o/cmake-build-debug/INSTALL/lib/libavcodec.a(libx264.o): In function `X264_frame':
/home/tiburcio/CLionProjects/awesom-o/cmake-build-debug/ffmpeg/libavcodec/libx264.c:340: undefined reference to `x264_encoder_encode'