當前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;
解決方法:
/////新增////////////
#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