1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/***
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 "encoder.h"
#include "ffmpeg/ffmpegencoder.h"
OLIVE_NAMESPACE_ENTER
Encoder::Encoder(const EncodingParams ¶ms) :
params_(params)
{
}
const EncodingParams &Encoder::params() const
{
return params_;
}
EncodingParams::EncodingParams() :
video_enabled_(false),
video_bit_rate_(0),
video_max_bit_rate_(0),
video_buffer_size_(0),
video_threads_(0),
audio_enabled_(false)
{
}
void EncodingParams::SetFilename(const QString &filename)
{
filename_ = filename;
}
void EncodingParams::EnableVideo(const VideoParams &video_params, const ExportCodec::Codec &vcodec)
{
video_enabled_ = true;
video_params_ = video_params;
video_codec_ = vcodec;
}
void EncodingParams::EnableAudio(const AudioParams &audio_params, const ExportCodec::Codec &acodec)
{
audio_enabled_ = true;
audio_params_ = audio_params;
audio_codec_ = acodec;
}
void EncodingParams::set_video_option(const QString &key, const QString &value)
{
video_opts_.insert(key, value);
}
void EncodingParams::set_video_bit_rate(const int64_t &rate)
{
video_bit_rate_ = rate;
}
void EncodingParams::set_video_max_bit_rate(const int64_t &rate)
{
video_max_bit_rate_ = rate;
}
void EncodingParams::set_video_buffer_size(const int64_t &sz)
{
video_buffer_size_ = sz;
}
void EncodingParams::set_video_threads(const int &threads)
{
video_threads_ = threads;
}
const QString &EncodingParams::filename() const
{
return filename_;
}
bool EncodingParams::video_enabled() const
{
return video_enabled_;
}
const ExportCodec::Codec &EncodingParams::video_codec() const
{
return video_codec_;
}
const VideoParams &EncodingParams::video_params() const
{
return video_params_;
}
const QHash<QString, QString> &EncodingParams::video_opts() const
{
return video_opts_;
}
const int64_t &EncodingParams::video_bit_rate() const
{
return video_bit_rate_;
}
const int64_t &EncodingParams::video_max_bit_rate() const
{
return video_max_bit_rate_;
}
const int64_t &EncodingParams::video_buffer_size() const
{
return video_buffer_size_;
}
const int &EncodingParams::video_threads() const
{
return video_threads_;
}
bool EncodingParams::audio_enabled() const
{
return audio_enabled_;
}
const ExportCodec::Codec &EncodingParams::audio_codec() const
{
return audio_codec_;
}
const AudioParams &EncodingParams::audio_params() const
{
return audio_params_;
}
const rational &EncodingParams::GetExportLength() const
{
return export_length_;
}
void EncodingParams::SetExportLength(const rational &export_length)
{
export_length_ = export_length;
}
void EncodingParams::Save(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("encode"));
writer->writeTextElement(QStringLiteral("filename"), filename_);
writer->writeStartElement(QStringLiteral("video"));
writer->writeAttribute(QStringLiteral("enabled"), QString::number(video_enabled_));
if (video_enabled_) {
writer->writeTextElement(QStringLiteral("codec"), QString::number(video_codec_));
writer->writeTextElement(QStringLiteral("width"), QString::number(video_params_.width()));
writer->writeTextElement(QStringLiteral("height"), QString::number(video_params_.height()));
writer->writeTextElement(QStringLiteral("format"), QString::number(video_params_.format()));
writer->writeTextElement(QStringLiteral("timebase"), video_params_.time_base().toString());
writer->writeTextElement(QStringLiteral("divider"), QString::number(video_params_.divider()));
writer->writeTextElement(QStringLiteral("bitrate"), QString::number(video_bit_rate_));
writer->writeTextElement(QStringLiteral("maxbitrate"), QString::number(video_max_bit_rate_));
writer->writeTextElement(QStringLiteral("bufsize"), QString::number(video_buffer_size_));
writer->writeTextElement(QStringLiteral("threads"), QString::number(video_threads_));
if (!video_opts_.isEmpty()) {
writer->writeStartElement(QStringLiteral("opts"));
QHash<QString, QString>::const_iterator i;
for (i=video_opts_.constBegin(); i!=video_opts_.constEnd(); i++) {
writer->writeStartElement(QStringLiteral("entry"));
writer->writeTextElement(QStringLiteral("key"), i.key());
writer->writeTextElement(QStringLiteral("value"), i.value());
writer->writeEndElement(); // entry
}
writer->writeEndElement(); // opts
}
}
writer->writeEndElement(); // video
writer->writeStartElement(QStringLiteral("audio"));
writer->writeAttribute(QStringLiteral("enabled"), QString::number(audio_enabled_));
if (audio_enabled_) {
writer->writeTextElement(QStringLiteral("codec"), QString::number(audio_codec_));
writer->writeTextElement(QStringLiteral("samplerate"), QString::number(audio_params_.sample_rate()));
writer->writeTextElement(QStringLiteral("channellayout"), QString::number(audio_params_.channel_layout()));
writer->writeTextElement(QStringLiteral("format"), QString::number(audio_params_.format()));
}
writer->writeEndElement(); // audio
writer->writeEndElement(); // encode
}
Encoder* Encoder::CreateFromID(const QString &id, const EncodingParams& params)
{
Q_UNUSED(id)
return new FFmpegEncoder(params);
}
OLIVE_NAMESPACE_EXIT
|