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

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

当前QT版本:5.12

编译器:MinGW 32位

QT的xxx.pro工程文件:

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库编译时出现错误如下:

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;

解决方法:

image.png

image.png

/新增
#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

目录
相关文章
|
2月前
|
机器学习/深度学习 并行计算 异构计算
WINDOWS安装eiseg遇到的问题和解决方法
通过本文的详细步骤和问题解决方法,希望能帮助你顺利在 Windows 系统上安装和运行 EISeg。
127 2
|
4月前
|
弹性计算 安全 网络安全
阿里云国际版无法远程连接Windows服务器的解决方法
阿里云国际版无法远程连接Windows服务器的解决方法
|
5月前
|
存储 编译器 程序员
QT源码学习 | 编译器知识点
本文是关于QT源码学习中编译器知识点的总结,包括`__declspec`、`Q_FUNC_INFO`、`__assume`、`__attribute__`、`__ASSEMBLER__`、`QT_SUPPORTS`和`QT_WARNING_DISABLE_MSVC`等宏定义的使用和作用,以及相关参考链接。
157 0
QT源码学习 | 编译器知识点
|
4月前
|
资源调度 编译器 Linux
Windows10系统安装Truffle框架,安装失败,提示:error An unexpected error occurred: “https://xxxxx
Windows10系统安装Truffle框架,安装失败,提示:error An unexpected error occurred: “https://xxxxx
125 0
|
5月前
|
Windows
Windows7电脑启动时提示文件winload.exe无法验证其数字签名,错误代码0xc0000428的解决方法
Windows7电脑启动时提示文件winload.exe无法验证其数字签名,错误代码0xc0000428的解决方法
|
6月前
|
PHP Windows
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
|
7月前
|
Oracle 关系型数据库 Linux
讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so
通过这一连串的步骤,可以专业且有效地在Linux下为Qt编译Oracle驱动库 `libqsqloci.so`,使得Qt应用能够通过OCI与Oracle数据库进行交互。这些步骤适用于具备一定Linux和Qt经验的开发者,并且能够为需要使用Qt开发数据库应用的专业人士提供指导。
232 1
讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so
|
6月前
|
API 开发工具 C语言
C语言与图形界面:利用GTK+、Qt等库创建GUI应用。
C语言与图形界面:利用GTK+、Qt等库创建GUI应用。
395 0
|
6月前
|
Linux Python Windows
【Azure 环境】Windows中安装Python azure-eventhub-checkpointstoreblob-aio模块时出错 ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory:
【Azure 环境】Windows中安装Python azure-eventhub-checkpointstoreblob-aio模块时出错 ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory:
|
7月前
|
安全 网络协议 Linux
【Windows】已解决:修改本地host文件异常的正确解决方法
【Windows】已解决:修改本地host文件异常的正确解决方法
448 0