export: allow selecting output pixel format

This commit is contained in:
itsmattkc
2020-07-24 14:45:27 +10:00
parent 86b66004b0
commit 5235975d6d
11 changed files with 183 additions and 55 deletions
+10
View File
@@ -88,6 +88,11 @@ void EncodingParams::set_video_threads(const int &threads)
video_threads_ = threads;
}
void EncodingParams::set_video_pix_fmt(const QString &s)
{
video_pix_fmt_ = s;
}
const QString &EncodingParams::filename() const
{
return filename_;
@@ -133,6 +138,11 @@ const int &EncodingParams::video_threads() const
return video_threads_;
}
const QString &EncodingParams::video_pix_fmt() const
{
return video_pix_fmt_;
}
bool EncodingParams::audio_enabled() const
{
return audio_enabled_;
+3
View File
@@ -51,6 +51,7 @@ public:
void set_video_max_bit_rate(const int64_t& rate);
void set_video_buffer_size(const int64_t& sz);
void set_video_threads(const int& threads);
void set_video_pix_fmt(const QString& s);
const QString& filename() const;
@@ -62,6 +63,7 @@ public:
const int64_t& video_max_bit_rate() const;
const int64_t& video_buffer_size() const;
const int& video_threads() const;
const QString& video_pix_fmt() const;
bool audio_enabled() const;
const ExportCodec::Codec &audio_codec() const;
@@ -83,6 +85,7 @@ private:
int64_t video_max_bit_rate_;
int64_t video_buffer_size_;
int video_threads_;
QString video_pix_fmt_;
bool audio_enabled_;
ExportCodec::Codec audio_codec_;
+50
View File
@@ -20,6 +20,11 @@
#include "exportcodec.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/pixdesc.h>
}
OLIVE_NAMESPACE_ENTER
QString ExportCodec::GetCodecName(ExportCodec::Codec c)
@@ -77,4 +82,49 @@ bool ExportCodec::IsCodecAStillImage(ExportCodec::Codec c)
return false;
}
QStringList ExportCodec::GetPixelFormatsForCodec(ExportCodec::Codec c)
{
QStringList pix_fmts;
AVCodec* codec_info;
switch (c) {
case kCodecH264:
codec_info = avcodec_find_encoder(AV_CODEC_ID_H264);
break;
case kCodecDNxHD:
codec_info = avcodec_find_encoder(AV_CODEC_ID_DNXHD);
break;
case kCodecProRes:
codec_info = avcodec_find_encoder(AV_CODEC_ID_PRORES);
break;
case kCodecH265:
codec_info = avcodec_find_encoder(AV_CODEC_ID_HEVC);
break;
case kCodecOpenEXR:
case kCodecPNG:
case kCodecTIFF:
// FIXME: Add these in (these will most likely use an OIIOEncoder which doesn't exist yet)
codec_info = nullptr;
break;
case kCodecMP2:
case kCodecMP3:
case kCodecAAC:
case kCodecPCM:
case kCodecCount:
// These are audio or invalid codecs and therefore have no pixel formats
codec_info = nullptr;
break;
}
if (codec_info) {
for (int i=0; codec_info->pix_fmts[i]!=-1; i++) {
const char* pix_fmt_name = av_get_pix_fmt_name(codec_info->pix_fmts[i]);
pix_fmts.append(pix_fmt_name);
}
}
return pix_fmts;
}
OLIVE_NAMESPACE_EXIT
+2
View File
@@ -51,6 +51,8 @@ public:
static bool IsCodecAStillImage(Codec c);
static QStringList GetPixelFormatsForCodec(Codec c);
};
OLIVE_NAMESPACE_EXIT
+5 -3
View File
@@ -20,6 +20,10 @@
#include "ffmpegencoder.h"
extern "C" {
#include <libavutil/pixdesc.h>
}
#include <QFile>
#include "ffmpegcommon.h"
@@ -441,9 +445,7 @@ bool FFmpegEncoder::InitializeStream(AVMediaType type, AVStream** stream_ptr, AV
codec_ctx->height = params().video_params().height();
codec_ctx->sample_aspect_ratio = {1, 1};
codec_ctx->time_base = params().video_params().time_base().toAVRational();
// FIXME: Make this customizable again
codec_ctx->pix_fmt = encoder->pix_fmts[0];
codec_ctx->pix_fmt = av_get_pix_fmt(params().video_pix_fmt().toUtf8());
// Set custom options
{