ffmpeg用g++编译时的注意事项
编译时出现以下错误:
错误一:
undefined reference to `av_register_all()'
undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)'
undefined reference to `avformat_find_stream_info(AVFormatContext*, AVDictionary**)'
undefined reference to `avcodec_find_decoder(AVCodecID)'
undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
undefined reference to `avcodec_alloc_frame()'
undefined reference to `avcodec_alloc_frame()'
解决方法:
用extern "C"{}把头文件包含起来。
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
错误二:
ffmpeg_4.0.2/lib/libavcodec.a(tiff.o): In function `tiff_uncompress_lzma':
ffmpeg-4.0.2/libavcodec/tiff.c:398: undefined reference to `lzma_stream_decoder'
ffmpeg-4.0.2/libavcodec/tiff.c:403: undefined reference to `lzma_code'
ffmpeg-4.0.2/libavcodec/tiff.c:404: undefined reference to `lzma_end'
解决方法:加上-llzma选项
参考的编译选项:
gcc push.cpp -g -I ffmpeg_4.0.2/include -L ffmpeg_4.0.2/lib -lavform个人中心at -lavcodec -lswresample -lavutil -pthread -lbz2 -lz -lm -llzma