sequence: rather than a static divider in config, default to a heuristically generated one
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -238,14 +238,17 @@ void Sequence::set_audio_params(const AudioParams ¶ms)
|
||||
|
||||
void Sequence::set_default_parameters()
|
||||
{
|
||||
set_video_params(VideoParams(Config::Current()["DefaultSequenceWidth"].toInt(),
|
||||
Config::Current()["DefaultSequenceHeight"].toInt(),
|
||||
Config::Current()["DefaultSequenceFrameRate"].value<rational>(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
Config::Current()["DefaultSequencePreviewDivider"].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()),
|
||||
VideoParams::generate_auto_divider(width, height)));
|
||||
set_audio_params(AudioParams(Config::Current()["DefaultSequenceAudioFrequency"].toInt(),
|
||||
Config::Current()["DefaultSequenceAudioLayout"].toULongLong(),
|
||||
SampleFormat::kInternalFormat));
|
||||
Config::Current()["DefaultSequenceAudioLayout"].toULongLong(),
|
||||
SampleFormat::kInternalFormat));
|
||||
}
|
||||
|
||||
void Sequence::set_parameters_from_footage(const QList<Footage *> footage)
|
||||
@@ -263,10 +266,10 @@ void Sequence::set_parameters_from_footage(const QList<Footage *> footage)
|
||||
// If this is a video stream, use these parameters
|
||||
if (!found_video_params && !vs->frame_rate().isNull()) {
|
||||
set_video_params(VideoParams(vs->width(),
|
||||
vs->height(),
|
||||
vs->frame_rate().flipped(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
|
||||
vs->height(),
|
||||
vs->frame_rate().flipped(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
VideoParams::generate_auto_divider(vs->width(), vs->height())));
|
||||
found_video_params = true;
|
||||
}
|
||||
break;
|
||||
@@ -278,10 +281,10 @@ void Sequence::set_parameters_from_footage(const QList<Footage *> footage)
|
||||
ImageStream* is = static_cast<ImageStream*>(s.get());
|
||||
|
||||
set_video_params(VideoParams(is->width(),
|
||||
is->height(),
|
||||
video_params().time_base(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
|
||||
is->height(),
|
||||
video_params().time_base(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
VideoParams::generate_auto_divider(is->width(), is->height())));
|
||||
}
|
||||
break;
|
||||
case Stream::kAudio:
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -85,17 +85,20 @@ void FootageViewerWidget::SetFootage(Footage *footage)
|
||||
if (video_stream) {
|
||||
video_node_->SetFootage(video_stream);
|
||||
viewer_node_->set_video_params(VideoParams(video_stream->width(),
|
||||
video_stream->height(),
|
||||
video_stream->frame_rate().flipped(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
Config::Current()["DefaultSequencePreviewDivider"].toInt()));
|
||||
video_stream->height(),
|
||||
video_stream->frame_rate().flipped(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].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(),
|
||||
Config::Current()["DefaultSequenceFrameRate"].value<rational>(),
|
||||
static_cast<PixelFormat::Format>(Config::Current()["DefaultSequencePreviewFormat"].toInt()),
|
||||
Config::Current()["DefaultSequencePreviewDivider"].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()),
|
||||
VideoParams::generate_auto_divider(width, height)));
|
||||
}
|
||||
|
||||
if (audio_stream) {
|
||||
@@ -104,8 +107,8 @@ void FootageViewerWidget::SetFootage(Footage *footage)
|
||||
NodeParam::ConnectEdge(audio_node_->output(), viewer_node_->samples_input());
|
||||
} else {
|
||||
viewer_node_->set_audio_params(AudioParams(Config::Current()["DefaultSequenceAudioFrequency"].toInt(),
|
||||
Config::Current()["DefaultSequenceAudioLayout"].toULongLong(),
|
||||
SampleFormat::kInternalFormat));
|
||||
Config::Current()["DefaultSequenceAudioLayout"].toULongLong(),
|
||||
SampleFormat::kInternalFormat));
|
||||
}
|
||||
|
||||
ConnectViewerNode(viewer_node_, footage_->project()->color_manager());
|
||||
|
||||
Reference in New Issue
Block a user