File indexing completed on 2025-01-05 03:57:32
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2022-03-17 0007 * Description : Methods to list FFMPEG features. 0008 * 0009 * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "ffmpegconfighelper.h" 0016 0017 // FFMpeg includes 0018 0019 extern "C" 0020 { 0021 #include <libavcodec/avcodec.h> 0022 #include <libavformat/avformat.h> 0023 } 0024 0025 namespace Digikam 0026 { 0027 0028 FFMpegProperties FFMpegConfigHelper::getVideoCodecsProperties() 0029 { 0030 FFMpegProperties props; 0031 0032 const AVCodec* vcodec = nullptr; 0033 0034 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 10, 100) 0035 0036 void* it = nullptr; 0037 0038 while ((vcodec = av_codec_iterate(&it))) 0039 0040 #else 0041 0042 avcodec_register_all(); 0043 0044 while ((vcodec = av_codec_next(vcodec))) 0045 0046 #endif 0047 0048 { 0049 if (vcodec->type != AVMEDIA_TYPE_VIDEO) 0050 { 0051 continue; 0052 } 0053 0054 QString name = QString::fromUtf8(vcodec->name); 0055 QStringList vals; 0056 0057 vals << QString::fromUtf8(vcodec->long_name); 0058 0059 if (av_codec_is_decoder(vcodec)) 0060 { 0061 vals << QLatin1String("R"); 0062 } 0063 else 0064 { 0065 vals << QLatin1String("X"); 0066 } 0067 0068 if (av_codec_is_encoder(vcodec)) 0069 { 0070 vals << QLatin1String("W"); 0071 } 0072 else 0073 { 0074 vals << QLatin1String("X"); 0075 } 0076 0077 props.insert(name, vals); 0078 } 0079 0080 return props; 0081 } 0082 0083 FFMpegProperties FFMpegConfigHelper::getAudioCodecsProperties() 0084 { 0085 FFMpegProperties props; 0086 0087 const AVCodec* acodec = nullptr; 0088 0089 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 10, 100) 0090 0091 void* it = nullptr; 0092 0093 while ((acodec = av_codec_iterate(&it))) 0094 0095 #else 0096 0097 avcodec_register_all(); 0098 0099 while ((acodec = av_codec_next(acodec))) 0100 0101 #endif 0102 0103 { 0104 if (acodec->type != AVMEDIA_TYPE_AUDIO) 0105 { 0106 continue; 0107 } 0108 0109 QString name = QString::fromUtf8(acodec->name); 0110 QStringList vals; 0111 0112 vals << QString::fromUtf8(acodec->long_name); 0113 0114 if (av_codec_is_decoder(acodec)) 0115 { 0116 vals << QLatin1String("R"); 0117 } 0118 else 0119 { 0120 vals << QLatin1String("X"); 0121 } 0122 0123 if (av_codec_is_encoder(acodec)) 0124 { 0125 vals << QLatin1String("W"); 0126 } 0127 else 0128 { 0129 vals << QLatin1String("X"); 0130 } 0131 0132 props.insert(name, vals); 0133 } 0134 0135 return props; 0136 } 0137 0138 FFMpegProperties FFMpegConfigHelper::getExtensionsProperties() 0139 { 0140 FFMpegProperties props; 0141 QStringList ext, exts; 0142 0143 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 10, 100) 0144 0145 const AVOutputFormat* outfmt = nullptr; 0146 void* it = nullptr; 0147 0148 while ((outfmt = av_muxer_iterate(&it))) 0149 0150 #else 0151 0152 av_register_all(); // Must register all input/output formats 0153 AVOutputFormat* outfmt = nullptr; 0154 0155 while ((outfmt = av_oformat_next(outfmt))) 0156 0157 #endif 0158 0159 { 0160 0161 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) 0162 0163 if (outfmt->extensions) 0164 { 0165 ext << QString::fromUtf8(outfmt->extensions).split(QLatin1Char(','), Qt::SkipEmptyParts); 0166 } 0167 0168 #else 0169 0170 if (outfmt->extensions) 0171 { 0172 ext << QString::fromUtf8(outfmt->extensions).split(QLatin1Char(','), QString::SkipEmptyParts); 0173 } 0174 0175 #endif 0176 0177 } 0178 0179 Q_FOREACH (const QString& val, ext) 0180 { 0181 exts.append(val.trimmed()); 0182 } 0183 0184 exts.removeDuplicates(); 0185 0186 Q_FOREACH (const QString& val, exts) 0187 { 0188 0189 outfmt = nullptr; 0190 0191 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 10, 100) 0192 0193 it = nullptr; 0194 0195 while ((outfmt = av_muxer_iterate(&it))) 0196 0197 #else 0198 0199 while ((outfmt = av_oformat_next(outfmt))) 0200 0201 #endif 0202 0203 { 0204 if (QString::fromUtf8(outfmt->extensions) == val) 0205 { 0206 props.insert(val, QStringList() << QString::fromUtf8(outfmt->long_name)); 0207 continue; 0208 } 0209 } 0210 } 0211 0212 return props; 0213 } 0214 0215 } // namespace Digikam