<div dir="ltr"><div>I'm trying to set-up a function, using the ffmpeg c api 2.7.2, to re-sample a stream (AVStream format) to fixed (1channel - u8 sample) format.</div><div><br></div><div>I'm using ffmpeg libswresample library, but when I try to compile, I get a linker error that is strictly connected to swresample functions.</div><div><br></div><div>Let me post the code:</div><div>----------------------------</div><div><div>double *resample8(AVFrame *frame, int size, AVCodec* codec){</div><div>    </div><div>    /* initialization of the output array */</div><div>    double *out = new double[size];</div><div><span class="Apple-tab-span" style="white-space:pre">  </span></div><div>    /* create resampling context */</div><div>    struct SwrContext *resampleContext;</div><div>    resampleContext = swr_alloc();</div><div>    if (!resampleContext) {</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>fprintf(stderr, "Could not allocate resampler context\n");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;</div><div>    }</div><div>    </div><div>    /* set options */</div><div>    av_opt_set_int(resampleContext, "in_channel_layout", *(codec->channel_layouts), 0);</div><div>    av_opt_set_sample_fmt(resampleContext, "in_sample_fmt", *(codec->sample_fmts), 0);</div><div><br></div><div>    av_opt_set_int(resampleContext, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);</div><div>    av_opt_set_sample_fmt(resampleContext, "out_sample_fmt", AV_SAMPLE_FMT_U8, 0);</div><div>    </div><div>    /* initialize the resampling context */</div><div>    if (swr_init(resampleContext) < 0) {</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>fprintf(stderr, "Failed to initialize the resampling context\n");</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>return NULL;</div><div>    }</div><div>    </div><div>    return NULL;</div><div>    </div><div>}</div></div><div>------------------------------------</div><div><br></div><div>Here is the inclusion:</div><div>------------------------------------</div><div><div>#ifdef __cplusplus</div><div>extern "C"</div><div>{</div><div>#endif // __cplusplus</div><div>    #include <libavcodec/avcodec.h></div><div>    #include <libavformat/avformat.h></div><div>    #include <libavutil/avutil.h></div><div>    #include <libavutil/opt.h></div><div>    #include <libavutil/channel_layout.h></div><div>    #include <libavutil/samplefmt.h></div><div>    #include <libswresample/swresample.h></div><div>#ifdef __cplusplus</div><div>} // end extern "C".</div><div>#endif // __cplusplus</div></div><div>----------------------------------</div><div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div><br></div><div>And here is the error I get, compiling with netbeans 8.0.2, g++ 4.9.2-10ubuntu13</div><div>(additional g++ commands: -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm)</div><div>----------------------------------    <br></div><div><div>"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf</div><div>make[1]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"</div><div>"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/audiosync</div><div>make[2]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"</div><div>mkdir -p build/Debug/GNU-Linux-x86</div><div>rm -f "build/Debug/GNU-Linux-x86/main.o.d"</div><div>g++    -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp</div><div>mkdir -p dist/Debug/GNU-Linux-x86</div><div>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</div><div>build/Debug/GNU-Linux-x86/dataReader.o: nella funzione "resample8(AVFrame*, int, AVCodec*)":</div><div>/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:285: riferimento non definito a "av_opt_set_sample_fmt"</div><div>/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:288: riferimento non definito a "av_opt_set_sample_fmt"</div><div>/usr/local/lib/libswresample.so: riferimento non definito a "av_calloc@LIBAVUTIL_54"</div><div>collect2: error: ld returned 1 exit status</div><div>nbproject/Makefile-Debug.mk:65: set di istruzioni per l'obiettivo "dist/Debug/GNU-Linux-x86/audiosync" non riuscito</div><div>make[2]: *** [dist/Debug/GNU-Linux-x86/audiosync] Errore 1</div><div>make[2]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"</div><div>nbproject/Makefile-Debug.mk:62: set di istruzioni per l'obiettivo ".build-conf" non riuscito</div><div>make[1]: *** [.build-conf] Errore 2</div><div>make[1]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"</div><div>nbproject/Makefile-impl.mk:39: set di istruzioni per l'obiettivo ".build-impl" non riuscito</div><div>make: *** [.build-impl] Errore 2</div><div><br></div><div>BUILD FAILED (exit value 2, total time: 5s)</div></div><div>------------------------------------------------------------</div><div><br></div><div>here is the linker configuration <a href="https://drive.google.com/file/d/0B2l6FPXN1f-EaEJfNmV2cjVUemM/view?usp=sharing">https://drive.google.com/file/d/0B2l6FPXN1f-EaEJfNmV2cjVUemM/view?usp=sharing</a></div><div><br></div><div>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 <a href="http://ffmpeg.org">ffmpeg.org</a></div><div><br></div><div>I can't seem to find a solution at the moment, can anyone help?</div></div>