【问题标题】:I am really confused with this kind of compilation error( C ffmpeg Qt)我真的对这种编译错误感到困惑(C ffmpeg Qt)
【发布时间】:2013-05-01 10:32:02
【问题描述】:

我下载了最新的ffmpeg源码并成功安装在Ubuntu上 但我未能编译一个简单的演示。(我确实包含了正确的标题)

以下是错误消息,仅举几例:

error: unknown type name 'AVFrame'

error: 'NULL' undeclared (first use in this function)

error: request for member 'streams' in something not a structure or union

error: 'AVMEDIA_TYPE_VIDEO' undeclared (first use in this function)

error: expected expression before ')' token

你能帮我解决这个问题吗?

添加的内容:

例如,这是我的包含

extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>
}

int main(int argc, char *argv[]) {
AVFormatContext *pFormatCtx;
int i, videoStreamIdx;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVFrame *pFrameRGB;

例如 AVFormatContext 在 /usr/include/libavformat/avformat.h 中声明 错误消息框显示未知类型名称 AVFormatContext 但怎么可能呢?

【问题讨论】:

  • 需要看一些代码。
  • 这里有一些附加信息 ffmpeg 版本 1.1.git 版权所有 (c) 2000-2013 FFmpeg 开发人员于 2013 年 5 月 7 日 14:10:58 使用 gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1 ) 配置: --enable-gpl --prefix=/usr --enable-libx264 --enable-pthreads 这是实际代码github.com/phamquy/FFmpeg-tu...r/tutorial01.c 这是在Qt 和Qt pro 文件中创建的。引用: QT -= gui TEMPLATE = app SOURCES += \ ../tutorial01.c LIBS += -L/-lavcodec -lavformat -lswscale -lavutil
  • 是的,上一个已关闭,标记为“不是真正的问题”。但它让我很烦恼,我需要修复它才能继续项目。谢谢。
  • 您说您包含正确的标头,但编译器似乎并不认为您是。也许您可以发布一些无法编译的代码;否则这只是你对编译器的反对。

标签: c++ linux qt compilation ffmpeg


【解决方案1】:

对于 C++ 代码,

extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/avutil.h"
}

对于 C 代码,

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>

C 和 C++ 编译成不同的代码集。

更多信息请参考这个答案:https://stackoverflow.com/a/67930/6180077

在main()或者程序的最开始,需要初始化ffmpeg库

av_register_all()  /*Initializes libavformat and registers all the muxers, demuxers and protocols. */

在编译程序时(比如 Ubuntu)

-L/$HOME/ffmpeg_build/lib/ -L/usr/lib/x86_64-linux-gnu/ -I/$HOME/ffmpeg_build/include/ myprogram.cpp -o executableFile -lavdevice -lavfilter -lswscale -lavformat -lavcodec -lavutil -lswresample

【讨论】:

    【解决方案2】:

    在 Qt 中,您可以将此行添加到您的 .pro 文件中,以强制编译器在那里查找头文件。将其更改为存储头文件的文件夹。

    INCLUDEPATH += &lt;your path&gt;

    【讨论】:

    • 我解决了这个问题。项目是用g++编译的,而源文件的后缀是.c,所以解决办法是改成.cpp
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2016-02-09
    • 1970-01-01
    • 2022-06-13
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多