Skip to content

Commit

Permalink
ffmpeg: user new format iterate api if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 8, 2018
1 parent 01f81df commit f9da1c3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
13 changes: 11 additions & 2 deletions src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 12 additions & 3 deletions src/AVMuxer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2015)
Expand Down Expand Up @@ -51,7 +51,9 @@ class AVMuxer::Private
, aenc(0)
, venc(0)
{
#if !AVFORMAT_STATIC_REGISTER
av_register_all();
#endif
}
~Private() {
//delete interrupt_hanlder;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/QtAV/private/AVCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extern "C"
#include <libavfilter/version.h>

#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 <libavutil/channel_layout.h>
Expand Down
17 changes: 14 additions & 3 deletions src/QtAV_Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,29 @@ QString avformatOptions()
void* obj = const_cast<void*>(reinterpret_cast<const void*>(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;
opts.append(QStringLiteral("options for input format %1:\n%2\n\n")
.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;
Expand Down
21 changes: 16 additions & 5 deletions src/subtitle/SubtitleProcessorFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit f9da1c3

Please sign in to comment.