@Saviz The example does not come copy-n-paste from the docs, it comes from reading the docs.
This will list all the combinations that are possible on the running platform concerned:
#include <QCoreApplication>
#include <QDebug>
#include <QMediaFormat>
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
const QList<QMediaFormat::FileFormat> containers = {
QMediaFormat::WMA, QMediaFormat::AAC, QMediaFormat::Matroska,
QMediaFormat::WMV, QMediaFormat::MP3, QMediaFormat::Wave,
QMediaFormat::Ogg, QMediaFormat::MPEG4, QMediaFormat::AVI,
QMediaFormat::QuickTime, QMediaFormat::WebM, QMediaFormat::Mpeg4Audio,
QMediaFormat::FLAC
};
const QList<QMediaFormat::AudioCodec> audioCodecs = {
QMediaFormat::AudioCodec::WMA, QMediaFormat::AudioCodec::AC3,
QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::ALAC,
QMediaFormat::AudioCodec::DolbyTrueHD, QMediaFormat::AudioCodec::EAC3,
QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::Wave,
QMediaFormat::AudioCodec::Vorbis, QMediaFormat::AudioCodec::FLAC,
QMediaFormat::AudioCodec::Opus, QMediaFormat::AudioCodec::Unspecified
};
const QList<QMediaFormat::VideoCodec> videoCodecs = {
QMediaFormat::VideoCodec::VP8, QMediaFormat::VideoCodec::MPEG2,
QMediaFormat::VideoCodec::MPEG1, QMediaFormat::VideoCodec::WMV,
QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::H264,
QMediaFormat::VideoCodec::MPEG4, QMediaFormat::VideoCodec::AV1,
QMediaFormat::VideoCodec::MotionJPEG, QMediaFormat::VideoCodec::VP9,
QMediaFormat::VideoCodec::Theora, QMediaFormat::VideoCodec::Unspecified
};
for (const auto &c : containers) {
QMediaFormat format(c);
for (const auto &v : videoCodecs) {
format.setVideoCodec(v);
for (const auto &a : audioCodecs) {
format.setAudioCodec(a);
if (format.isSupported(QMediaFormat::Encode)) {
qDebug() << QMediaFormat::fileFormatName(c) << "("
<< QMediaFormat::videoCodecName(v) << ", "
<< QMediaFormat::audioCodecName(a) << ")";
}
}
}
}
return 0;
}
If you only want to support "closely aligned" combinations then only check those.
There's no direct connection between the container format and the name of the file it is contained in. This is done purely by convention. If you want to put an MPEG4 container with audio-only in a file called blah.acc then go right ahead. Most players, I assume, only use this as a hint as to the file content and actually read the content to determine what is sane to do.