diff options
Diffstat (limited to 'src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp')
-rw-r--r-- | src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp index 0ff4cc68b..6389b4eed 100644 --- a/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp +++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp @@ -1,49 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qffmpegmediaformatinfo_p.h" -#include "qffmpeg_p.h" #include "qaudioformat.h" #include "qimagewriter.h" +#include <qloggingcategory.h> + QT_BEGIN_NAMESPACE +static Q_LOGGING_CATEGORY(qLcMediaFormatInfo, "qt.multimedia.ffmpeg.mediaformatinfo") + static struct { AVCodecID id; QMediaFormat::VideoCodec codec; @@ -162,7 +129,7 @@ static const AVOutputFormat *avFormatForFormat(QMediaFormat::FileFormat format) QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() { - qDebug() << ">>>> listing codecs"; + qCDebug(qLcMediaFormatInfo) << ">>>> listing codecs"; QList<QMediaFormat::AudioCodec> audioEncoders; QList<QMediaFormat::AudioCodec> extraAudioDecoders; @@ -171,8 +138,8 @@ QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() const AVCodecDescriptor *descriptor = nullptr; while ((descriptor = avcodec_descriptor_next(descriptor))) { - bool canEncode = (avcodec_find_encoder(descriptor->id) != nullptr); - bool canDecode = (avcodec_find_decoder(descriptor->id) != nullptr); + const bool canEncode = QFFmpeg::findAVEncoder(descriptor->id) != nullptr; + const bool canDecode = QFFmpeg::findAVDecoder(descriptor->id) != nullptr; auto videoCodec = videoCodecForAVCodecId(descriptor->id); auto audioCodec = audioCodecForAVCodecId(descriptor->id); if (descriptor->type == AVMEDIA_TYPE_VIDEO && videoCodec != QMediaFormat::VideoCodec::Unspecified) { @@ -183,9 +150,8 @@ QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() if (!extraVideoDecoders.contains(videoCodec)) extraVideoDecoders.append(videoCodec); } - } - - else if (descriptor->type == AVMEDIA_TYPE_AUDIO && audioCodec != QMediaFormat::AudioCodec::Unspecified) { + } else if (descriptor->type == AVMEDIA_TYPE_AUDIO + && audioCodec != QMediaFormat::AudioCodec::Unspecified) { if (canEncode) { if (!audioEncoders.contains(audioCodec)) audioEncoders.append(audioCodec); @@ -197,14 +163,14 @@ QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() } // get demuxers -// qDebug() << ">>>> Muxers"; +// qCDebug(qLcMediaFormatInfo) << ">>>> Muxers"; void *opaque = nullptr; const AVOutputFormat *outputFormat = nullptr; while ((outputFormat = av_muxer_iterate(&opaque))) { auto mediaFormat = formatForAVFormat(outputFormat); if (mediaFormat == QMediaFormat::UnspecifiedFormat) continue; -// qDebug() << " mux:" << outputFormat->name << outputFormat->long_name << outputFormat->mime_type << outputFormat->extensions << mediaFormat; +// qCDebug(qLcMediaFormatInfo) << " mux:" << outputFormat->name << outputFormat->long_name << outputFormat->mime_type << outputFormat->extensions << mediaFormat; CodecMap encoder; encoder.format = mediaFormat; @@ -214,7 +180,7 @@ QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() // only add the codec if it can be used with this container if (avformat_query_codec(outputFormat, id, FF_COMPLIANCE_NORMAL) == 1) { // add codec for container -// qDebug() << " " << codec << Qt::hex << av_codec_get_tag(outputFormat->codec_tag, id); +// qCDebug(qLcMediaFormatInfo) << " " << codec << Qt::hex << av_codec_get_tag(outputFormat->codec_tag, id); encoder.audio.append(codec); } } @@ -223,7 +189,7 @@ QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() // only add the codec if it can be used with this container if (avformat_query_codec(outputFormat, id, FF_COMPLIANCE_NORMAL) == 1) { // add codec for container -// qDebug() << " " << codec << Qt::hex << av_codec_get_tag(outputFormat->codec_tag, id); +// qCDebug(qLcMediaFormatInfo) << " " << codec << Qt::hex << av_codec_get_tag(outputFormat->codec_tag, id); encoder.video.append(codec); } } @@ -258,7 +224,16 @@ QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo() // can encode. That's a safe subset. decoders = encoders; -// qDebug() << "extraDecoders:" << extraAudioDecoders << extraVideoDecoders; +#ifdef Q_OS_WINDOWS + // MediaFoundation HVEC encoder fails when processing frames + for (auto &encoder : encoders) { + auto h265index = encoder.video.indexOf(QMediaFormat::VideoCodec::H265); + if (h265index >= 0) + encoder.video.removeAt(h265index); + } +#endif + +// qCDebug(qLcMediaFormatInfo) << "extraDecoders:" << extraAudioDecoders << extraVideoDecoders; // FFmpeg can currently only decode WMA and WMV, not encode if (extraAudioDecoders.contains(QMediaFormat::AudioCodec::WMA)) { decoders[QMediaFormat::WMA].audio.append(QMediaFormat::AudioCodec::WMA); @@ -524,11 +499,17 @@ QAudioFormat QFFmpegMediaFormatInfo::audioFormatFromCodecParameters(AVCodecParam QAudioFormat format; format.setSampleFormat(sampleFormat(AVSampleFormat(codecpar->format))); format.setSampleRate(codecpar->sample_rate); - - auto channelLayout = codecpar->channel_layout; +#if QT_FFMPEG_OLD_CHANNEL_LAYOUT + uint64_t channelLayout = codecpar->channel_layout; if (!channelLayout) channelLayout = avChannelLayout(QAudioFormat::defaultChannelConfigForChannelCount(codecpar->channels)); - +#else + uint64_t channelLayout = 0; + if (codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) + channelLayout = codecpar->ch_layout.u.mask; + else + channelLayout = avChannelLayout(QAudioFormat::defaultChannelConfigForChannelCount(codecpar->ch_layout.nb_channels)); +#endif format.setChannelConfig(channelConfigForAVLayout(channelLayout)); return format; } |