diff --git a/src/AVDemuxer.cpp b/src/AVDemuxer.cpp index d48ac8cf2..301b8eb9f 100644 --- a/src/AVDemuxer.cpp +++ b/src/AVDemuxer.cpp @@ -332,7 +332,9 @@ AVDemuxer::AVDemuxer(QObject *parent) #if QTAV_HAVE(AVDEVICE) avdevice_register_all(); #endif +#if !AVFORMAT_STATIC_REGISTER av_register_all(); +#endif avformat_network_init(); } ~AVInitializer() { @@ -354,10 +356,15 @@ static void getFFmpegInputFormats(QStringList* formats, QStringList* extensions) static QStringList exts; static QStringList fmts; if (exts.isEmpty() && fmts.isEmpty()) { - av_register_all(); // MUST register all input/output formats - AVInputFormat *i = NULL; QStringList e, f; + const AVInputFormat *i = NULL; +#if AVFORMAT_STATIC_REGISTER + void* it = NULL; + while ((i = av_demuxer_iterate(&it))) { +#else + av_register_all(); // MUST register all input/output formats while ((i = av_iformat_next(i))) { +#endif if (i->extensions) e << QString::fromLatin1(i->extensions).split(QLatin1Char(','), QString::SkipEmptyParts); if (i->name) @@ -402,7 +409,9 @@ const QStringList &AVDemuxer::supportedProtocols() #if QTAV_HAVE(AVDEVICE) protocols << QStringLiteral("avdevice"); #endif +#if !AVFORMAT_STATIC_REGISTER av_register_all(); // MUST register all input/output formats +#endif void* opq = 0; const char* protocol = avio_enum_protocols(&opq, 0); while (protocol) { diff --git a/src/AVMuxer.cpp b/src/AVMuxer.cpp index d2eb3dde8..17b16de10 100644 --- a/src/AVMuxer.cpp +++ b/src/AVMuxer.cpp @@ -1,6 +1,6 @@ /****************************************************************************** QtAV: Multimedia framework based on Qt and FFmpeg - Copyright (C) 2012-2016 Wang Bin + Copyright (C) 2012-2018 Wang Bin * This file is part of QtAV (from 2015) @@ -51,7 +51,9 @@ class AVMuxer::Private , aenc(0) , venc(0) { +#if !AVFORMAT_STATIC_REGISTER av_register_all(); +#endif } ~Private() { //delete interrupt_hanlder; @@ -186,10 +188,15 @@ static void getFFmpegOutputFormats(QStringList* formats, QStringList* extensions static QStringList exts; static QStringList fmts; if (exts.isEmpty() && fmts.isEmpty()) { - av_register_all(); // MUST register all input/output formats - AVOutputFormat *o = NULL; QStringList e, f; + const AVOutputFormat *o = NULL; +#if AVFORMAT_STATIC_REGISTER + void* it = NULL; + while ((o = av_muxer_iterate(&it))) { +#else + av_register_all(); // MUST register all input/output formats while ((o = av_oformat_next(o))) { +#endif if (o->extensions) e << QString::fromLatin1(o->extensions).split(QLatin1Char(','), QString::SkipEmptyParts); if (o->name) @@ -239,7 +246,9 @@ const QStringList &AVMuxer::supportedProtocols() #if QTAV_HAVE(AVDEVICE) protocols << QStringLiteral("avdevice"); #endif +#if !AVFORMAT_STATIC_REGISTER av_register_all(); // MUST register all input/output formats +#endif void* opq = 0; const char* protocol = avio_enum_protocols(&opq, 1); while (protocol) { diff --git a/src/QtAV/private/AVCompat.h b/src/QtAV/private/AVCompat.h index 51afbb780..9ef99b9eb 100644 --- a/src/QtAV/private/AVCompat.h +++ b/src/QtAV/private/AVCompat.h @@ -62,6 +62,7 @@ extern "C" #include #define AVCODEC_STATIC_REGISTER FFMPEG_MODULE_CHECK(LIBAVCODEC, 58, 10, 100) +#define AVFORMAT_STATIC_REGISTER FFMPEG_MODULE_CHECK(LIBAVFORMAT, 58, 9, 100) #if !FFMPEG_MODULE_CHECK(LIBAVUTIL, 51, 73, 101) #include diff --git a/src/QtAV_Global.cpp b/src/QtAV_Global.cpp index 07ea14a29..60505cd1f 100644 --- a/src/QtAV_Global.cpp +++ b/src/QtAV_Global.cpp @@ -275,9 +275,14 @@ QString avformatOptions() void* obj = const_cast(reinterpret_cast(avformat_get_class())); opts = Internal::optionsToString((void*)&obj); opts.append(ushort('\n')); - av_register_all(); - AVInputFormat *i = NULL; + const AVInputFormat *i = NULL; +#if AVFORMAT_STATIC_REGISTER + void* it = NULL; + while ((i = av_demuxer_iterate(&it))) { +#else + av_register_all(); // MUST register all input/output formats while ((i = av_iformat_next(i))) { +#endif QString opt(Internal::optionsToString((void*)&i->priv_class).trimmed()); if (opt.isEmpty()) continue; @@ -285,8 +290,14 @@ QString avformatOptions() .arg(QLatin1String(i->name)) .arg(opt)); } - AVOutputFormat *o = NULL; + const AVOutputFormat *o = NULL; +#if AVFORMAT_STATIC_REGISTER + it = NULL; + while ((o = av_muxer_iterate(&it))) { +#else + av_register_all(); // MUST register all input/output formats while ((o = av_oformat_next(o))) { +#endif QString opt(Internal::optionsToString((void*)&o->priv_class).trimmed()); if (opt.isEmpty()) continue; diff --git a/src/subtitle/SubtitleProcessorFFmpeg.cpp b/src/subtitle/SubtitleProcessorFFmpeg.cpp index 32d9c8ffd..b610bced0 100644 --- a/src/subtitle/SubtitleProcessorFFmpeg.cpp +++ b/src/subtitle/SubtitleProcessorFFmpeg.cpp @@ -91,8 +91,14 @@ QStringList ffmpeg_supported_sub_extensions_by_codec() if (c->type != AVMEDIA_TYPE_SUBTITLE) continue; qDebug("sub codec: %s", c->name); - AVInputFormat *i = av_iformat_next(NULL); - while (i) { + const AVInputFormat *i = NULL; +#if AVFORMAT_STATIC_REGISTER + void* it2 = NULL; + while ((i = av_demuxer_iterate(&it2))) { +#else + av_register_all(); // MUST register all input/output formats + while ((i = av_iformat_next(i))) { +#endif if (!strcmp(i->name, c->name)) { qDebug("found iformat"); if (i->extensions) { @@ -103,7 +109,6 @@ QStringList ffmpeg_supported_sub_extensions_by_codec() } break; } - i = av_iformat_next(i); } if (!i) { //qDebug("codec name '%s' is not found in AVInputFormat, just append codec name", c->name); @@ -116,8 +121,14 @@ QStringList ffmpeg_supported_sub_extensions_by_codec() QStringList ffmpeg_supported_sub_extensions() { QStringList exts; - AVInputFormat *i = NULL; + const AVInputFormat *i = NULL; +#if AVFORMAT_STATIC_REGISTER + void* it = NULL; + while ((i = av_demuxer_iterate(&it))) { +#else + av_register_all(); // MUST register all input/output formats while ((i = av_iformat_next(i))) { +#endif // strstr parameters can not be null if (i->long_name && strstr(i->long_name, "subtitle")) { if (i->extensions) { @@ -131,7 +142,7 @@ QStringList ffmpeg_supported_sub_extensions() QStringList codecs; const AVCodec* c = NULL; #if AVCODEC_STATIC_REGISTER - void* it = NULL; + it = NULL; while ((c = av_codec_iterate(&it))) { #else avcodec_register_all();