首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >windows下在QT里调用ffmpeg库处理音频视频数据时,出现error missing -D__STDC_FORMAT_MACROS 错误的解决方法(MINGW32编译器)。

windows下在QT里调用ffmpeg库处理音频视频数据时,出现error missing -D__STDC_FORMAT_MACROS 错误的解决方法(MINGW32编译器)。

作者头像
DS小龙哥
发布2022-01-12 11:07:57
发布2022-01-12 11:07:57
2.9K0
举报

当前QT版本:5.12

编译器:MinGW 32位

QT的xxx.pro工程文件:

代码语言:javascript
复制
QT       += core gui
QT       += multimediawidgets
QT       += xml
QT       += multimedia
QT       += network
QT       += widgets
QT       += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    Color_conversion.cpp \
    audio_video_encode_0.cpp \
    ffmpeg_code.cpp \
    main.cpp \
    widget.cpp

HEADERS += \
    Color_conversion.h \
    audio_video_encode_0.h \
    config.h \
    ffmpeg_code.h \
    widget.h

FORMS += \
    widget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RC_ICONS=log.ico

win32
{
    message('运行win32版本')
    INCLUDEPATH+=$$PWD/ffmpeg-win32-shared-dll/include
    LIBS+=$$PWD/ffmpeg-win32-shared-dll/bin/av*
    LIBS+=$$PWD/ffmpeg-win32-shared-dll/bin/sw*
    LIBS+=$$PWD/ffmpeg-win32-shared-dll/bin/pos*
}

RESOURCES += \
    image.qrc

调用FFMEGE库编译时出现错误如下:

代码语言:javascript
复制
In file included from ..\ffmpeg_save_video\ffmpeg_code.h:33:0,
                 from ..\ffmpeg_save_video\ffmpeg_code.cpp:1:
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:30:2: error: #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
 #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
  ^~~~~
In file included from ..\ffmpeg_save_video\ffmpeg_code.h:33:0,
                 from ..\ffmpeg_save_video\audio_video_encode_0.h:4,
                 from ..\ffmpeg_save_video\audio_video_encode_0.cpp:2:
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:30:2: error: #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
 #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
  ^~~~~
In file included from ..\ffmpeg_save_video\ffmpeg_code.h:33:0,
                 from ..\ffmpeg_save_video\audio_video_encode_0.h:4,
                 from ..\ffmpeg_save_video\widget.h:30,
                 from ..\ffmpeg_save_video\main.cpp:1:
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:30:2: error: #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
 #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
  ^~~~~
In file included from ..\ffmpeg_save_video\ffmpeg_code.h:33:0,
                 from ..\ffmpeg_save_video\audio_video_encode_0.h:4,
                 from ..\ffmpeg_save_video\widget.h:30,
                 from ..\ffmpeg_save_video\widget.cpp:1:
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:30:2: error: #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
 #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
  ^~~~~
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h: In function 'char* av_ts_make_string(char*, int64_t)':
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:46:76: warning: conversion lacks type at end of format [-Wformat=]
     else                      snprintf(buf, AV_TS_MAX_STRING_SIZE, "%l", ts);
                                                                            ^
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:46:76: warning: too many arguments for format [-Wformat-extra-args]
mingw32-make[1]: *** [Makefile.Release:980: release/Color_conversion.o] Error 1
mingw32-make[1]: *** Waiting for unfinished jobs....
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h: In function 'char* av_ts_make_string(char*, int64_t)':
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:46:76: warning: conversion lacks type at end of format [-Wformat=]
     else                      snprintf(buf, AV_TS_MAX_STRING_SIZE, "%l", ts);
                                                                            ^
..\ffmpeg_save_video\ffmpeg-win32-shared-dll\include/libavutil/timestamp.h:46:76: warning: too many arguments for format [-Wformat-extra-args]
..\ffmpeg_save_video\ffmpeg_code.cpp: In function 'void ffmpeg_open_audio(AVFormatContext*, AVCodec*, OutputStream*, AVDictionary*)':
..\ffmpeg_save_video\ffmpeg_code.cpp:92:41: warning: unused parameter 'oc' [-Wunused-parameter]
 void ffmpeg_open_audio(AVFormatContext *oc,
                                         ^~
..\ffmpeg_save_video\ffmpeg_code.cpp: In function 'int ffmpeg_write_audio_frame(AVFormatContext*, OutputStream*, AVFrame* (*)(OutputStream*))':
..\ffmpeg_save_video\ffmpeg_code.cpp:153:24: warning: missing initializer for member 'AVPacket::pts' [-Wmissing-field-initializers]
     AVPacket pkt = { 0 }; // data and size must be 0;

解决方法:

代码语言:javascript
复制
/新增
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

#if defined __cplusplus
#define __STDC_CONSTANT_MACROS  //common.h中的错误
#define __STDC_FORMAT_MACROS    //timestamp.h中的错误
#endif
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/04/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档