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

目录
相关文章
|
1月前
|
Go Windows
windows安装scoop/annie下载B站等视频
windows安装scoop/annie下载B站等视频
61 0
|
14天前
|
前端开发
自定义QT QWidget对象响应弹出菜单的解决方法
自定义QT QWidget对象响应弹出菜单的解决方法
24 1
|
22天前
|
Windows
如何使用Windows Media Player刻录数据DVD
Windows Media Player是微软Windows系统自带的多媒体播放器,支持多种音频、视频格式及图片查看,也能接收网络广播和刻录CD/DVD。用户可利用它管理媒体文件、创建播放列表。然而,其刻录DVD功能有限,仅适用于数据DVD。若需创建可在DVD播放机上播放的视频DVD,建议使用专业软件如DVDFab DVD Creator。
|
29天前
|
数据库 Windows
第五十章 使用 ^SystemPerformance 监视性能 - Microsoft Windows 平台的 InterSystems IRIS 性能数据报告
第五十章 使用 ^SystemPerformance 监视性能 - Microsoft Windows 平台的 InterSystems IRIS 性能数据报告
25 0
|
1月前
|
编译器 C++ Windows
QT5构建套件检测不到MSVC2017解决方法
QT5构建套件检测不到MSVC2017解决方法
102 0
|
1月前
|
存储 Kubernetes 安全
虚拟机测试Windows Server 2016原地升级2019,应用和数据完美保留
Windows Server 2016可以无缝升级到2019版本,确保应用程序和数据在原地升级过程中完整保留。
168 0
|
1月前
|
关系型数据库 MySQL Java
windows下mybatis插入mysql数据中文乱码问题解决
windows下mybatis插入mysql数据中文乱码问题解决
117 0
|
6月前
|
存储 数据安全/隐私保护 Windows
4.5 Windows驱动开发:内核中实现进程数据转储
多数ARK反内核工具中都存在驱动级别的内存转存功能,该功能可以将应用层中运行进程的内存镜像转存到特定目录下,内存转存功能在应对加壳程序的分析尤为重要,当进程在内存中解码后,我们可以很容易的将内存镜像导出,从而更好的对样本进行分析,当然某些加密壳可能无效但绝大多数情况下是可以被转存的。
33 0
4.5 Windows驱动开发:内核中实现进程数据转储
|
1月前
|
Windows
Windows【工具 01】视频下载工具BBDown.exe详细使用说明(https://github.com/nilaoda/BBDown)mp4格式无法识别问题处理(最新版本1.6.1网盘分享)
Windows【工具 01】视频下载工具BBDown.exe详细使用说明(https://github.com/nilaoda/BBDown)mp4格式无法识别问题处理(最新版本1.6.1网盘分享)
258 0
|
1月前
|
开发工具
使用FFmpeg4.3.1的SDK官方开发包编译ffmpeg.c(三)
使用FFmpeg4.3.1的SDK官方开发包编译ffmpeg.c(三)
40 0

推荐镜像

更多