FFMPEG communication error
I am trying to compile a modified version of this transcoding example from the FFMPEG site , I have used all the required included and linked libs using this:
INCLUDEPATH += $$(FFMPEG_DEV_PATH)\include
LIBS += -L$$(FFMPEG_DEV_PATH)\lib -lavformat -lavcodec -lavutil -lswscale -liconv -lz -lavfilter
but I am getting this communication error which I cannot understand:
"avio_close(AVIOContext*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"av_strerror(int, char*, unsigned long)", referenced from:
av_make_error_string(char*, unsigned long, int) in PhVideoEncoder.o
"av_rescale_q(long long, AVRational, AVRational)", referenced from:
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"av_frame_free(AVFrame**)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"av_read_frame(AVFormatContext*, AVPacket*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avcodec_close(AVCodecContext*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)", referenced from:
PhVideoEncoder::open_input_file(char const*) in PhVideoEncoder.o
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"av_dump_format(AVFormatContext*, int, char const*, int)", referenced from:
PhVideoEncoder::open_input_file(char const*) in PhVideoEncoder.o
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"av_frame_alloc()", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
"av_free_packet(AVPacket*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"av_init_packet(AVPacket*)", referenced from:
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"av_opt_set_bin(void*, char const*, unsigned char const*, int, int)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"av_register_all()", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"av_rescale_q_rnd(long long, AVRational, AVRational, AVRounding)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"av_write_trailer(AVFormatContext*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avfilter_graph_free(AVFilterGraph**)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avfilter_inout_free(AVFilterInOut**)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avformat_new_stream(AVFormatContext*, AVCodec const*)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)", referenced from:
PhVideoEncoder::open_input_file(char const*) in PhVideoEncoder.o
"avcodec_copy_context(AVCodecContext*, AVCodecContext const*)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"avcodec_find_decoder(AVCodecID)", referenced from:
PhVideoEncoder::open_input_file(char const*) in PhVideoEncoder.o
"avcodec_find_encoder(AVCodecID)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"avfilter_get_by_name(char const*)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avfilter_graph_alloc()", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avfilter_inout_alloc()", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avformat_close_input(AVFormatContext**)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, AVPacket const*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avcodec_decode_video2(AVCodecContext*, AVFrame*, int*, AVPacket const*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avcodec_encode_audio2(AVCodecContext*, AVPacket*, AVFrame const*, int*)", referenced from:
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"avcodec_encode_video2(AVCodecContext*, AVPacket*, AVFrame const*, int*)", referenced from:
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"avfilter_graph_config(AVFilterGraph*, void*)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avfilter_register_all()", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avformat_free_context(AVFormatContext*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"avformat_write_header(AVFormatContext*, AVDictionary**)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"av_get_sample_fmt_name(AVSampleFormat)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"av_buffersink_get_frame(AVFilterContext*, AVFrame*)", referenced from:
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
"avfilter_graph_parse_ptr(AVFilterGraph*, char const*, AVFilterInOut**, AVFilterInOut**, void*)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avformat_find_stream_info(AVFormatContext*, AVDictionary**)", referenced from:
PhVideoEncoder::open_input_file(char const*) in PhVideoEncoder.o
"av_interleaved_write_frame(AVFormatContext*, AVPacket*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
"av_buffersrc_add_frame_flags(AVFilterContext*, AVFrame*, int)", referenced from:
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
"avfilter_graph_create_filter(AVFilterContext**, AVFilter const*, char const*, char const*, void*, AVFilterGraph*)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"av_get_default_channel_layout(int)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avformat_alloc_output_context2(AVFormatContext**, AVOutputFormat*, char const*, char const*)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"av_get_channel_layout_nb_channels(unsigned long long)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
"av_frame_get_best_effort_timestamp(AVFrame const*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"av_log(void*, int, char const*, ...)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
PhVideoEncoder::flush_encoder(unsigned int) in PhVideoEncoder.o
PhVideoEncoder::open_input_file(char const*) in PhVideoEncoder.o
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
PhVideoEncoder::encode_write_frame(AVFrame*, unsigned int, int*) in PhVideoEncoder.o
...
"av_free(void*)", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"av_malloc(unsigned long)", referenced from:
av_malloc_array(unsigned long, unsigned long) in PhVideoEncoder.o
"av_strdup(char const*)", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"avio_open(AVIOContext**, char const*, int)", referenced from:
PhVideoEncoder::open_output_file(char const*) in PhVideoEncoder.o
I tried looking for missing libraries but no luck ... What am I missing?
EDIT
Thanks to the first answer, I added stuff extern C
, but I still run into a few errors:
Undefined symbols for architecture x86_64:
"_av_buffersink_get_frame", referenced from:
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
"_av_buffersrc_add_frame_flags", referenced from:
PhVideoEncoder::filter_encode_write_frame(AVFrame*, unsigned int) in PhVideoEncoder.o
"_avfilter_get_by_name", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_graph_alloc", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_graph_config", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_graph_create_filter", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_graph_free", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
"_avfilter_graph_parse_ptr", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_inout_alloc", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_inout_free", referenced from:
PhVideoEncoder::init_filter(FilteringContext*, AVCodecContext*, AVCodecContext*, char const*) in PhVideoEncoder.o
"_avfilter_register_all", referenced from:
PhVideoEncoder::PhVideoEncoder(QString) in PhVideoEncoder.o
ld: symbol(s) not found for architecture x86_64
source to share
See this post - most likely, when mixing C ++ code with FFMPEG C interface, you forgot the keyword extern "C"
, so the linker uses the C ++ function name failure and thus cannot find references. You must enable FFMPEG in the extern "C"
following way:
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
source to share
The link to the FFmpeg site with a transcoding example is now broken, but you can find it here: http://ffmpeg.org/doxygen/trunk/doc_2examples_2transcoding_8c-example.html
I think the problem is that this example uses a later version of FFmpeg. I am using Android FFmpeg 1.0 port from https://github.com/appunite/AndroidFFmpeg and I am also facing the same problems (uneclared for example avfilter_graph_parse_ptr
). My FFmpeg source code doesn't have it, but declares it instead avfilter_graph_parse
.
My source code doesn't have an example of transcoding, I think doc / examples / decoding_encoding.c should be used instead .
I changed the code to use old functions, for example av_frame_free
→ avcodec_free_frame
, av_buffersrc_write_frame_flags
→ av_buffersrc_write_frame
etc. now it at least compiles ...
source to share