FFmpeg libswresample链接器错误

时间:2015-08-02 19:57:38

标签: c++ audio ffmpeg linker

我尝试使用ffmpeg c api设置一个函数,将流(AVStream格式)重新采样为固定(1channel - u8样本)格式。

我正在使用ffmpeg libswresample库,但是当我尝试编译时,我得到一个严格连接到swresample函数的链接器错误。

让我发布代码:

double *resample8(AVFrame *frame, int size, AVCodec* codec){

    /* initialization of the output array */
    double *out = new double[size];

    /* create resampling context */
    struct SwrContext *resampleContext;
    resampleContext = swr_alloc();
    if (!resampleContext) {
    fprintf(stderr, "Could not allocate resampler context\n");
    return NULL;
    }

    /* set options */
    av_opt_set_int(resampleContext, "in_channel_layout", *(codec->channel_layouts), 0);
    av_opt_set_sample_fmt(resampleContext, "in_sample_fmt", *(codec->sample_fmts), 0);

    av_opt_set_int(resampleContext, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);
    av_opt_set_sample_fmt(resampleContext, "out_sample_fmt", AV_SAMPLE_FMT_U8, 0);

    /* initialize the resampling context */
    if (swr_init(resampleContext) < 0) {
    fprintf(stderr, "Failed to initialize the resampling context\n");
    return NULL;
    }

    return NULL;

}

以下是包含:

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
    #include <libavutil/opt.h>
    #include <libavutil/channel_layout.h>
    #include <libavutil/samplefmt.h>
    #include <libswresample/swresample.h>
#ifdef __cplusplus
} // end extern "C".
#endif // __cplusplus

这是我得到的错误,用netbeans编译,g ++ (其他g ++命令:-lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm)

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/audiosync
make[2]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/audiosync build/Debug/GNU-Linux-x86/dataReader.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/tansforms.o build/Debug/GNU-Linux-x86/tognuplot.o  -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm
build/Debug/GNU-Linux-x86/dataReader.o: nella funzione "resample8(AVFrame*, int, AVCodec*)":
/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:285: riferimento non definito a "av_opt_set_sample_fmt"
/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:288: riferimento non definito a "av_opt_set_sample_fmt"
/usr/local/lib/libswresample.so: riferimento non definito a "av_calloc@LIBAVUTIL_54"
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:65: set di istruzioni per l'obiettivo "dist/Debug/GNU-Linux-x86/audiosync" non riuscito
make[2]: *** [dist/Debug/GNU-Linux-x86/audiosync] Errore 1
make[2]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
nbproject/Makefile-Debug.mk:62: set di istruzioni per l'obiettivo ".build-conf" non riuscito
make[1]: *** [.build-conf] Errore 2
make[1]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
nbproject/Makefile-impl.mk:39: set di istruzioni per l'obiettivo ".build-impl" non riuscito
make: *** [.build-impl] Errore 2

BUILD FAILED (exit value 2, total time: 5s)

这是链接器配置linker config

我搜索了有关链接器错误的任何线索,我发现它可能是由安装了多个版本的ffmpeg引起的。我删除了ubuntu(我使用15.04)基本安装ffmpeg并从ffmpeg.org下载的tar安装了ffmpeg 2.7.2

我现在似乎无法找到解决方案,任何人都可以提供帮助吗?

1 个答案:

答案 0 :(得分:-1)

我认为链接顺序很重要 提到这个问题 Why does the order in which libraries are linked sometimes cause errors in GCC?

尝试此订单

libavdevice libavformat libavfilter libavcodec libwscale libavutil libswresample libswscale libpostproc libavresample