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

目录
相关文章
|
机器学习/深度学习 人工智能 测试技术
VisionTS:基于时间序列的图形构建高性能时间序列预测模型,利用图像信息进行时间序列预测
构建预训练时间序列模型的主要挑战在于获取高质量、多样化的时间序列数据。目前有两种方法:迁移学习LLM(如GPT-4或Llama)和从零训练。尽管迁移学习可行,但效果有限;从零训练则依赖大量数据,如MOIRAI、TimesFM和TTM等模型所示。为解决这一难题,研究人员提出利用图像数据进行时间序列预测。
854 11
VisionTS:基于时间序列的图形构建高性能时间序列预测模型,利用图像信息进行时间序列预测
|
机器学习/深度学习 人工智能 自然语言处理
探索深度学习在游戏开发中的创新应用
【8月更文挑战第11天】深度学习技术在游戏开发中的应用为游戏产业带来了前所未有的变革和机遇。通过不断探索和创新应用,我们有理由相信未来的游戏将会更加智能、丰富和引人入胜。
|
数据库 Python
PqQt实现对数据库的添加,删除,修改(完整过程演示
PqQt实现对数据库的添加,删除,修改(完整过程演示
1481 0
|
API C# 图形学
程序技术好文:深入理解xLua热更新原理
程序技术好文:深入理解xLua热更新原理
660 0
|
Web App开发 JSON 数据格式
【Azure Developer】浏览器查看本地数据文件时遇见跨域问题(CORS)
Access to XMLHttpRequest at 'file:///C:/Users/.../failedrequests.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome-untrusted, https, edge. reportdata/failedrequests.json:1 Fail
223 1
|
数据采集 监控 物联网
IOT/智能设备日志解决方案(1):概述
无论是物联网还是智能设备,规模都越来越大,产业分工也越来越明确,逐渐形成一整套的生态系统。而同时无论是物联网还是智能设备的生态系统中,日志数据永远是不可缺少的一个重要环节。
6191 0
IOT/智能设备日志解决方案(1):概述
|
运维 Linux Shell
Linux之自动化运维工具ansible、ansible模块(1)
Linux之自动化运维工具ansible、ansible模块(1)
|
运维 API C#
【Unity游戏破解】外挂原理分析
【Unity游戏破解】外挂原理分析
1224 0
【Unity游戏破解】外挂原理分析
|
Web App开发 分布式计算 数据挖掘
基于Spark的网上商城用户行为分析
基于Spark的网上商城用户行为分析
|
存储 JavaScript 前端开发
Vue2:组件高级(上)
Vue2:组件高级(上)
336 1
Vue2:组件高级(上)