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

目录
相关文章
|
5月前
Qt6.5打包(QT windeployqt不是内部或外部命令、QT错误:缺少libgcc_s_seh-1.dll ,无法正常启动(0xc000007b) 问题解决方法)
Qt6.5打包(QT windeployqt不是内部或外部命令、QT错误:缺少libgcc_s_seh-1.dll ,无法正常启动(0xc000007b) 问题解决方法)
657 1
|
6月前
|
计算机视觉 Windows
OpenCV + CLion在windows环境下使用CMake编译, 出现Mutex相关的错误的解决办法
OpenCV + CLion在windows环境下使用CMake编译, 出现Mutex相关的错误的解决办法
274 0
QT编译警告 warning LNK4042: 对象被多次指定;已忽略多余的指定
QT编译警告 warning LNK4042: 对象被多次指定;已忽略多余的指定
270 0
|
Linux C语言 Windows
编译Windows版本ffmpeg:MingW方式失败
编译Windows版本ffmpeg:MingW方式失败
116 0
编译Windows版本ffmpeg:MingW方式失败
|
C语言 C++ Windows
编译Windows版本ffmpeg:msys2方式失败
编译Windows版本ffmpeg:msys2方式失败
180 0
编译Windows版本ffmpeg:msys2方式失败
|
计算机视觉 Python
关于最新版本的Anaconda里面的Spyder里总出现 ‘DLL load failed: 找不到指定的模块’ 的问题
关于最新版本的Anaconda里面的Spyder里总出现 ‘DLL load failed: 找不到指定的模块’ 的问题
关于最新版本的Anaconda里面的Spyder里总出现 ‘DLL load failed: 找不到指定的模块’ 的问题
|
Windows
WINDOWS/cygwin编译lame出错:error: ‘_O_BINARY‘ undeclared
WINDOWS/cygwin编译lame出错:error: ‘_O_BINARY‘ undeclared
166 0
|
编译器 计算机视觉
关于 Qt编译时使用msvc编译器报错“Error: cannot open ...main.obj.10836.32.jom for write” 的解决方法
关于 Qt编译时使用msvc编译器报错“Error: cannot open ...main.obj.10836.32.jom for write” 的解决方法
关于 Qt编译时使用msvc编译器报错“Error: cannot open ...main.obj.10836.32.jom for write” 的解决方法
【QT】解决VS开发QT程序,切换至release版本提示找不到相关头文件。
【QT】解决VS开发QT程序,切换至release版本提示找不到相关头文件。
【QT】解决VS开发QT程序,切换至release版本提示找不到相关头文件。
|
Linux 计算机视觉
关于 编译qt项目时报错:error: cannot find -lGLESv2 的解决方法
关于 编译qt项目时报错:error: cannot find -lGLESv2 的解决方法