为什么ffmpeg cmake外部项目无法正常工作

时间:2019-03-24 14:35:50

标签: c++ ffmpeg cmake

我正在尝试将具有h264支持的ffmpeg编译为外部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'

0 个答案:

没有答案