sequence: rather than a static divider in config, default to a heuristically generated one

This commit is contained in:
itsmattkc
2020-06-08 15:18:01 +10:00
parent 430561e2ac
commit 50b4c1e456
8 changed files with 85 additions and 28 deletions
-1
View File
@@ -110,7 +110,6 @@ void Config::SetDefaults()
config_map_["DefaultSequenceAudioFrequency"] = 48000;
config_map_["DefaultSequenceAudioLayout"] = QVariant::fromValue(static_cast<uint64_t>(AV_CH_LAYOUT_STEREO));
config_map_["DefaultSequencePreviewFormat"] = PixelFormat::PIX_FMT_RGBA16F;
config_map_["DefaultSequencePreviewDivider"] = 3;
// Online/offline settings
config_map_["OnlinePixelFormat"] = PixelFormat::PIX_FMT_RGBA32F;
+5
View File
@@ -809,6 +809,11 @@ QList<uint64_t> Core::SupportedChannelLayouts()
return channel_layouts;
}
QList<int> Core::SupportedDividers()
{
return {1, 2, 3, 4, 6, 8, 12, 16};
}
QString Core::FrameRateToString(const rational &frame_rate)
{
return tr("%1 FPS").arg(frame_rate.toDouble());
+5
View File
@@ -178,6 +178,11 @@ public:
*/
static QList<uint64_t> SupportedChannelLayouts();
/**
* @brief Return a list of supported dividers
*/
static QList<int> SupportedDividers();
/**
* @brief Convert rational frame rate (i.e. flipped timebase) to a user-friendly string
*/
@@ -90,7 +90,7 @@ SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidg
}
// Set up preview dividers
divider_list_ = {1, 2, 3, 4, 6, 8, 12, 16};
divider_list_ = Core::SupportedDividers();
foreach (int d, divider_list_) {
QString name;
+8 -5
View File
@@ -238,11 +238,14 @@ void Sequence::set_audio_params(const AudioParams &params)
void Sequence::set_default_parameters()
{
set_video_params(VideoParams(Config::Current()["DefaultSequenceWidth"].toInt(),
Config::Current()["DefaultSequenceHeight"].toInt(),
int width = Config::Current()["DefaultSequenceWidth"].toInt();
int height = Config::Current()["DefaultSequenceHeight"].toInt();
set_video_params(VideoParams(width,
height,
Config::Current()["DefaultSequenceFrameRate"].value<rational>(),
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
VideoParams::generate_auto_divider(width, height)));
set_audio_params(AudioParams(Config::Current()["DefaultSequenceAudioFrequency"].toInt(),
Config::Current()["DefaultSequenceAudioLayout"].toULongLong(),
SampleFormat::kInternalFormat));
@@ -266,7 +269,7 @@ void Sequence::set_parameters_from_footage(const QList<Footage *> footage)
vs->height(),
vs->frame_rate().flipped(),
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
VideoParams::generate_auto_divider(vs->width(), vs->height())));
found_video_params = true;
}
break;
@@ -281,7 +284,7 @@ void Sequence::set_parameters_from_footage(const QList<Footage *> footage)
is->height(),
video_params().time_base(),
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
VideoParams::generate_auto_divider(is->width(), is->height())));
}
break;
case Stream::kAudio:
+40
View File
@@ -22,6 +22,8 @@
#include <QtMath>
#include "core.h"
OLIVE_NAMESPACE_ENTER
VideoParams::VideoParams() :
@@ -48,6 +50,44 @@ VideoParams::VideoParams(const int &width, const int &height, const rational &ti
calculate_effective_size();
}
int VideoParams::generate_auto_divider(qint64 width, qint64 height)
{
// Arbitrary pixel count (from 640x360)
const int target_res = 230400;
qint64 megapixels = width * height;
double squared_divider = double(megapixels) / double(target_res);
double divider = qSqrt(squared_divider);
QList<int> supported_dividers = Core::SupportedDividers();
if (divider <= supported_dividers.first()) {
return supported_dividers.first();
} else if (divider >= supported_dividers.last()) {
return supported_dividers.last();
} else {
for (int i=1; i<supported_dividers.size(); i++) {
int prev_divider = supported_dividers.at(i-1);
int next_divider = supported_dividers.at(i);
if (divider >= prev_divider && divider <= next_divider) {
double prev_diff = qAbs(prev_divider - divider);
double next_diff = qAbs(next_divider - divider);
if (prev_diff < next_diff) {
return prev_divider;
} else {
return next_divider;
}
}
}
// "Safe" fallback
return 2;
}
}
bool VideoParams::operator==(const VideoParams &rhs) const
{
return width() == rhs.width()
+2
View File
@@ -68,6 +68,8 @@ public:
return format_;
}
static int generate_auto_divider(qint64 width, qint64 height);
bool is_valid() const;
bool operator==(const VideoParams& rhs) const;
+7 -4
View File
@@ -88,14 +88,17 @@ void FootageViewerWidget::SetFootage(Footage *footage)
video_stream->height(),
video_stream->frame_rate().flipped(),
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
VideoParams::generate_auto_divider(video_stream->width(), video_stream->height())));
NodeParam::ConnectEdge(video_node_->output(), viewer_node_->texture_input());
} else {
viewer_node_->set_video_params(VideoParams(Config::Current()["DefaultSequenceWidth"].toInt(),
Config::Current()["DefaultSequenceHeight"].toInt(),
int width = Config::Current()["DefaultSequenceWidth"].toInt();
int height = Config::Current()["DefaultSequenceHeight"].toInt();
viewer_node_->set_video_params(VideoParams(width,
height,
Config::Current()["DefaultSequenceFrameRate"].value<rational>(),
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
VideoParams::generate_auto_divider(width, height)));
}
if (audio_stream) {