export: use codec IDs rather than strings

Vastly improves portability between library versions.
This commit is contained in:
itsmattkc
2020-05-21 03:04:38 +10:00
parent d5766489e4
commit 0cf6c9a1f6
13 changed files with 347 additions and 194 deletions
+4
View File
@@ -23,6 +23,10 @@ set(OLIVE_SOURCES
codec/decoder.cpp
codec/encoder.h
codec/encoder.cpp
codec/exportcodec.h
codec/exportcodec.cpp
codec/exportformat.h
codec/exportformat.cpp
codec/frame.h
codec/frame.cpp
codec/samplebuffer.h
+4 -4
View File
@@ -49,14 +49,14 @@ void EncodingParams::SetFilename(const QString &filename)
filename_ = filename;
}
void EncodingParams::EnableVideo(const VideoRenderingParams &video_params, const QString &vcodec)
void EncodingParams::EnableVideo(const VideoRenderingParams &video_params, const ExportCodec::Codec &vcodec)
{
video_enabled_ = true;
video_params_ = video_params;
video_codec_ = vcodec;
}
void EncodingParams::EnableAudio(const AudioRenderingParams &audio_params, const QString &acodec)
void EncodingParams::EnableAudio(const AudioRenderingParams &audio_params, const ExportCodec::Codec &acodec)
{
audio_enabled_ = true;
audio_params_ = audio_params;
@@ -98,7 +98,7 @@ bool EncodingParams::video_enabled() const
return video_enabled_;
}
const QString &EncodingParams::video_codec() const
const ExportCodec::Codec &EncodingParams::video_codec() const
{
return video_codec_;
}
@@ -138,7 +138,7 @@ bool EncodingParams::audio_enabled() const
return audio_enabled_;
}
const QString &EncodingParams::audio_codec() const
const ExportCodec::Codec &EncodingParams::audio_codec() const
{
return audio_codec_;
}
+8 -6
View File
@@ -24,6 +24,8 @@
#include <memory>
#include <QString>
#include "codec/exportcodec.h"
#include "codec/exportformat.h"
#include "codec/frame.h"
#include "common/timerange.h"
#include "render/audioparams.h"
@@ -40,8 +42,8 @@ public:
void SetFilename(const QString& filename);
void EnableVideo(const VideoRenderingParams& video_params, const QString& vcodec);
void EnableAudio(const AudioRenderingParams& audio_params, const QString& acodec);
void EnableVideo(const VideoRenderingParams& video_params, const ExportCodec::Codec& vcodec);
void EnableAudio(const AudioRenderingParams& audio_params, const ExportCodec::Codec &acodec);
void set_video_option(const QString& key, const QString& value);
void set_video_bit_rate(const int64_t& rate);
@@ -52,7 +54,7 @@ public:
const QString& filename() const;
bool video_enabled() const;
const QString& video_codec() const;
const ExportCodec::Codec& video_codec() const;
const VideoRenderingParams& video_params() const;
const QHash<QString, QString>& video_opts() const;
const int64_t& video_bit_rate() const;
@@ -61,7 +63,7 @@ public:
const int& video_threads() const;
bool audio_enabled() const;
const QString& audio_codec() const;
const ExportCodec::Codec &audio_codec() const;
const AudioRenderingParams& audio_params() const;
const rational& GetExportLength() const;
@@ -71,7 +73,7 @@ private:
QString filename_;
bool video_enabled_;
QString video_codec_;
ExportCodec::Codec video_codec_;
VideoRenderingParams video_params_;
QHash<QString, QString> video_opts_;
int64_t video_bit_rate_;
@@ -80,7 +82,7 @@ private:
int video_threads_;
bool audio_enabled_;
QString audio_codec_;
ExportCodec::Codec audio_codec_;
AudioRenderingParams audio_params_;
rational export_length_;
+80
View File
@@ -0,0 +1,80 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "exportcodec.h"
OLIVE_NAMESPACE_ENTER
QString ExportCodec::GetCodecName(ExportCodec::Codec c)
{
switch (c) {
case kCodecDNxHD:
return tr("DNxHD");
case kCodecH264:
return tr("H.264");
case kCodecH265:
return tr("H.265");
case kCodecOpenEXR:
return tr("OpenEXR");
case kCodecPNG:
return tr("PNG");
case kCodecProRes:
return tr("ProRes");
case kCodecTIFF:
return tr("TIFF");
case kCodecMP2:
return tr("MP2");
case kCodecMP3:
return tr("MP3");
case kCodecAAC:
return tr("AAC");
case kCodecPCM:
return tr("PCM (Uncompressed)");
case kCodecCount:
break;
}
return tr("Unknown");
}
bool ExportCodec::IsCodecAStillImage(ExportCodec::Codec c)
{
switch (c) {
case kCodecDNxHD:
case kCodecH264:
case kCodecH265:
case kCodecProRes:
case kCodecMP2:
case kCodecMP3:
case kCodecAAC:
case kCodecPCM:
return false;
case kCodecOpenEXR:
case kCodecPNG:
case kCodecTIFF:
return true;
case kCodecCount:
break;
}
return false;
}
OLIVE_NAMESPACE_EXIT
+58
View File
@@ -0,0 +1,58 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef EXPORTCODEC_H
#define EXPORTCODEC_H
#include <QObject>
#include <QString>
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
class ExportCodec : public QObject {
public:
enum Codec {
kCodecDNxHD,
kCodecH264,
kCodecH265,
kCodecOpenEXR,
kCodecPNG,
kCodecProRes,
kCodecTIFF,
kCodecMP2,
kCodecMP3,
kCodecAAC,
kCodecPCM,
kCodecCount
};
static QString GetCodecName(Codec c);
static bool IsCodecAStillImage(Codec c);
};
OLIVE_NAMESPACE_EXIT
#endif // EXPORTCODEC_H
+138
View File
@@ -0,0 +1,138 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "exportformat.h"
OLIVE_NAMESPACE_ENTER
QString ExportFormat::GetName(olive::ExportFormat::Format f)
{
switch (f) {
case kFormatDNxHD:
return tr("DNxHD");
case kFormatMatroska:
return tr("Matroska Video");
case kFormatMPEG4:
return tr("MPEG-4 Video");
case kFormatOpenEXR:
return tr("OpenEXR");
case kFormatPNG:
return tr("PNG");
case kFormatTIFF:
return tr("TIFF");
case kFormatQuickTime:
return tr("QuickTime");
case kFormatCount:
break;
}
return tr("Unknown");
}
QString ExportFormat::GetExtension(ExportFormat::Format f)
{
switch (f) {
case kFormatDNxHD:
return QStringLiteral("mxf");
case kFormatMatroska:
return QStringLiteral("mkv");
case kFormatMPEG4:
return QStringLiteral("mp4");
case kFormatOpenEXR:
return QStringLiteral("exr");
case kFormatPNG:
return QStringLiteral("png");
case kFormatTIFF:
return QStringLiteral("tiff");
case kFormatQuickTime:
return QStringLiteral("mov");
case kFormatCount:
break;
}
return QString();
}
QString ExportFormat::GetEncoder(ExportFormat::Format f)
{
switch (f) {
case kFormatDNxHD:
case kFormatMatroska:
case kFormatQuickTime:
case kFormatMPEG4:
return QStringLiteral("ffmpeg");
case kFormatOpenEXR:
case kFormatPNG:
case kFormatTIFF:
return QStringLiteral("oiio");
case kFormatCount:
break;
}
return QString();
}
QList<ExportCodec::Codec> ExportFormat::GetVideoCodecs(ExportFormat::Format f)
{
switch (f) {
case kFormatDNxHD:
return {ExportCodec::kCodecDNxHD};
case kFormatMatroska:
return {ExportCodec::kCodecH264, ExportCodec::kCodecH265};
case kFormatMPEG4:
return {ExportCodec::kCodecH264, ExportCodec::kCodecH265};
case kFormatOpenEXR:
return {ExportCodec::kCodecOpenEXR};
case kFormatPNG:
return {ExportCodec::kCodecPNG};
case kFormatTIFF:
return {ExportCodec::kCodecTIFF};
case kFormatQuickTime:
return {ExportCodec::kCodecH264, ExportCodec::kCodecH265, ExportCodec::kCodecProRes};
case kFormatCount:
break;
}
return {};
}
QList<ExportCodec::Codec> ExportFormat::GetAudioCodecs(ExportFormat::Format f)
{
switch (f) {
case kFormatDNxHD:
return {ExportCodec::kCodecPCM};
case kFormatMatroska:
return {ExportCodec::kCodecAAC, ExportCodec::kCodecMP2, ExportCodec::kCodecMP3, ExportCodec::kCodecPCM};
case kFormatMPEG4:
return {ExportCodec::kCodecAAC, ExportCodec::kCodecMP2, ExportCodec::kCodecMP3, ExportCodec::kCodecPCM};
case kFormatQuickTime:
return {ExportCodec::kCodecAAC, ExportCodec::kCodecMP2, ExportCodec::kCodecMP3, ExportCodec::kCodecPCM};
case kFormatOpenEXR:
case kFormatPNG:
case kFormatTIFF:
return {};
case kFormatCount:
break;
}
return {};
}
OLIVE_NAMESPACE_EXIT
+56
View File
@@ -0,0 +1,56 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef EXPORTFORMAT_H
#define EXPORTFORMAT_H
#include <QList>
#include <QString>
#include "common/define.h"
#include "exportcodec.h"
OLIVE_NAMESPACE_ENTER
class ExportFormat : public QObject {
public:
enum Format {
kFormatDNxHD,
kFormatMatroska,
kFormatMPEG4,
kFormatOpenEXR,
kFormatQuickTime,
kFormatPNG,
kFormatTIFF,
kFormatCount
};
static QString GetName(Format f);
static QString GetExtension(Format f);
static QString GetEncoder(Format f);
static QList<ExportCodec::Codec> GetVideoCodecs(ExportFormat::Format f);
static QList<ExportCodec::Codec> GetAudioCodecs(ExportFormat::Format f);
};
OLIVE_NAMESPACE_EXIT
#endif // EXPORTFORMAT_H
+43 -5
View File
@@ -362,19 +362,57 @@ fail:
return succeeded;
}
bool FFmpegEncoder::InitializeStream(AVMediaType type, AVStream** stream_ptr, AVCodecContext** codec_ctx_ptr, const QString& codec)
bool FFmpegEncoder::InitializeStream(AVMediaType type, AVStream** stream_ptr, AVCodecContext** codec_ctx_ptr, const ExportCodec::Codec& codec)
{
if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
Error(QStringLiteral("Cannot initialize a stream that is not a video or audio type"));
return false;
}
// Retrieve codec and convert to C string
QByteArray codec_bytes = codec.toUtf8();
const char* codec_c_str = codec_bytes.constData();
// Retrieve codec
AVCodecID codec_id;
switch (codec) {
case ExportCodec::kCodecDNxHD:
codec_id = AV_CODEC_ID_DNXHD;
break;
case ExportCodec::kCodecAAC:
codec_id = AV_CODEC_ID_AAC;
break;
case ExportCodec::kCodecMP2:
codec_id = AV_CODEC_ID_MP2;
break;
case ExportCodec::kCodecMP3:
codec_id = AV_CODEC_ID_MP3;
break;
case ExportCodec::kCodecH264:
codec_id = AV_CODEC_ID_H264;
break;
case ExportCodec::kCodecH265:
codec_id = AV_CODEC_ID_HEVC;
break;
case ExportCodec::kCodecOpenEXR:
codec_id = AV_CODEC_ID_EXR;
break;
case ExportCodec::kCodecPNG:
codec_id = AV_CODEC_ID_PNG;
break;
case ExportCodec::kCodecTIFF:
codec_id = AV_CODEC_ID_TIFF;
break;
case ExportCodec::kCodecProRes:
codec_id = AV_CODEC_ID_PRORES;
break;
case ExportCodec::kCodecPCM:
codec_id = AV_CODEC_ID_PCM_S16LE;
break;
case ExportCodec::kCodecCount:
Error(QStringLiteral("Unknown internal codec"));
return false;
}
// Find encoder with this name
AVCodec* encoder = avcodec_find_encoder_by_name(codec_c_str);
AVCodec* encoder = avcodec_find_encoder(codec_id);
if (!encoder) {
Error(QStringLiteral("Failed to find codec for %1").arg(codec));
+1 -1
View File
@@ -69,7 +69,7 @@ private:
bool WriteAVFrame(AVFrame* frame, AVCodecContext *codec_ctx, AVStream *stream);
bool InitializeStream(enum AVMediaType type, AVStream** stream, AVCodecContext** codec_ctx, const QString& codec);
bool InitializeStream(enum AVMediaType type, AVStream** stream, AVCodecContext** codec_ctx, const ExportCodec::Codec &codec);
bool InitializeCodecContext(AVStream** stream, AVCodecContext** codec_ctx, AVCodec* codec);
bool SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx, AVCodec *codec);
+6
View File
@@ -35,6 +35,12 @@ class OIIODecoder : public Decoder
public:
OIIODecoder();
enum ExportCodec {
kCodecEXR,
kCodecPNG,
kCodecTIFF
};
virtual QString id() override;
virtual bool Probe(Footage *f, const QAtomicInt* cancelled) override;