未定义的avcodec_alloc_context参考但ffmpeg链接器顺序是否正确?

 老屋时光_503 发布于 2023-01-01 18:05

我想构建静态链接到libavcodec和libavformat的静态链接可执行文件.静态ffmpeg库是用以下代码构建的:

./configure --enable-static --enable-gpl --enable-nonfree --disable-vaapi 
     --disable-libopus --prefix=myBuild --disable-swresample

接头设置如下:

g++ -O2 -static -o myBin myBin-myBin.o someotherlibraries.a 
     -L/ffmpeg/myBuild/lib -lavformat -lavcodec -lavutil  -lrt -lm -lpthread -lz

编译时,我收到一条错误消息>: - /

src/ffmpeg/myProgram.cpp:115: error: undefined reference to 'avcodec_alloc_context'

输出nm /ffmpeg/myBuild/lib/libavcodec.a | grep avcodec_alloc_context:

         U avcodec_alloc_context3
         U avcodec_alloc_context3
000003c0 T avcodec_alloc_context3
         U avcodec_alloc_context3

我包含带有extern"C"{}的libavcodec.h,我相信我的静态链接器顺序是正确的.为什么我会收到此错误?是因为这个方法已被弃用了吗?我怎么解决这个问题?

解:

不要用

avCtx = avcodec_alloc_context()

从可能较旧的代码片段,但使用

codec = avcodec_find_decoder(CODEC_ID_XYZ);//for completeness but should be the same as before
avCtx = avcodec_alloc_context3(codec)

Non-maskable.. 6

您是否尝试过调用avcodec_alloc_context3?

我遇到没有问题调用avcodec_alloc_context3,分配extradata然后调用avcodec_open2.

链接顺序也应该是-lavutil -lavformat -lavcodec

1 个回答
  • 您是否尝试过调用avcodec_alloc_context3?

    我遇到没有问题调用avcodec_alloc_context3,分配extradata然后调用avcodec_open2.

    链接顺序也应该是-lavutil -lavformat -lavcodec

    2023-01-01 18:07 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有