0

I'm trying to set-up a function, using the ffmpeg c api, to re-sample a stream (AVStream format) to fixed (1channel - u8 sample) format.

I'm using ffmpeg libswresample library, but when I try to compile, I get a linker error that is strictly connected to swresample functions.

Let me post the code:

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;

}

Here is the inclusion:

#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

And here is the error I get, compiling with netbeans, g++ (additional g++ commands: -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)

here is the linker configuration linker config

I searched for any clue about the linker error, and I found that it could be caused by multiple versions of ffmpeg installed. I removed ubuntu (I'm using 15.04) base installation of ffmpeg and installed ffmpeg 2.7.2 from the tar downloaded by ffmpeg.org

I can't seem to find a solution at the moment, can anyone help?

1 Answers1

-1

I think the linking order matters refer this question Why does the order in which libraries are linked sometimes cause errors in GCC?

Try this order

libavdevice libavformat libavfilter libavcodec libwscale libavutil libswresample libswscale libpostproc libavresample
Community
  • 1
  • 1