various: implement sequence pixel aspect ratios and interlacing settings
Implements the following: - Sequences have pixel aspect ratios that work in tandem with footage PARs to render footage correctly. Viewer and export also acknowledge PARs - Sequences can have interlacing settings. This doesn't do anything yet, eventually the renderer will need to interlace/deinterlace/reinterlace appropriately in order to conform all the footage to the sequence. Export acknowledges interlacing, but this only affects metadata, not the image.
This commit is contained in:
@@ -24,8 +24,31 @@ extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
const QVector<int> AudioParams::kSupportedSampleRates = {
|
||||
8000, // 8000 Hz
|
||||
11025, // 11025 Hz
|
||||
16000, // 16000 Hz
|
||||
22050, // 22050 Hz
|
||||
24000, // 24000 Hz
|
||||
32000, // 32000 Hz
|
||||
44100, // 44100 Hz
|
||||
48000, // 48000 Hz
|
||||
88200, // 88200 Hz
|
||||
96000 // 96000 Hz
|
||||
};
|
||||
|
||||
const QVector<uint64_t> AudioParams::kSupportedChannelLayouts = {
|
||||
AV_CH_LAYOUT_MONO,
|
||||
AV_CH_LAYOUT_STEREO,
|
||||
AV_CH_LAYOUT_2_1,
|
||||
AV_CH_LAYOUT_5POINT1,
|
||||
AV_CH_LAYOUT_7POINT1
|
||||
};
|
||||
|
||||
int AudioParams::time_to_bytes(const double &time) const
|
||||
{
|
||||
Q_ASSERT(is_valid());
|
||||
@@ -127,4 +150,27 @@ bool AudioParams::is_valid() const
|
||||
&& format_ != SampleFormat::SAMPLE_FMT_COUNT);
|
||||
}
|
||||
|
||||
QString AudioParams::SampleRateToString(const int &sample_rate)
|
||||
{
|
||||
return QCoreApplication::translate("AudioParams", "%1 Hz").arg(sample_rate);
|
||||
}
|
||||
|
||||
QString AudioParams::ChannelLayoutToString(const uint64_t &layout)
|
||||
{
|
||||
switch (layout) {
|
||||
case AV_CH_LAYOUT_MONO:
|
||||
return QCoreApplication::translate("AudioParams", "Mono");
|
||||
case AV_CH_LAYOUT_STEREO:
|
||||
return QCoreApplication::translate("AudioParams", "Stereo");
|
||||
case AV_CH_LAYOUT_2_1:
|
||||
return QCoreApplication::translate("AudioParams", "2.1");
|
||||
case AV_CH_LAYOUT_5POINT1:
|
||||
return QCoreApplication::translate("AudioParams", "5.1");
|
||||
case AV_CH_LAYOUT_7POINT1:
|
||||
return QCoreApplication::translate("AudioParams", "7.1");
|
||||
default:
|
||||
return QCoreApplication::translate("AudioParams", "Unknown (0x%1)").arg(layout, 1, 16);
|
||||
}
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -80,6 +80,19 @@ public:
|
||||
bool operator==(const AudioParams& other) const;
|
||||
bool operator!=(const AudioParams& other) const;
|
||||
|
||||
static const QVector<uint64_t> kSupportedChannelLayouts;
|
||||
static const QVector<int> kSupportedSampleRates;
|
||||
|
||||
/**
|
||||
* @brief Convert integer sample rate to a user-friendly string
|
||||
*/
|
||||
static QString SampleRateToString(const int &sample_rate);
|
||||
|
||||
/**
|
||||
* @brief Convert channel layout to a user-friendly string
|
||||
*/
|
||||
static QString ChannelLayoutToString(const uint64_t &layout);
|
||||
|
||||
private:
|
||||
int sample_rate_;
|
||||
|
||||
|
||||
@@ -149,22 +149,26 @@ QVariant OpenGLProxy::FrameToValue(FramePtr frame, StreamPtr stream, const Video
|
||||
VideoParams frame_params = frame->video_params();
|
||||
|
||||
// Check frame aspect ratio
|
||||
if (frame->sample_aspect_ratio() != 1) {
|
||||
rational true_pixel_aspect_ratio = frame_params.pixel_aspect_ratio() / params.pixel_aspect_ratio();
|
||||
|
||||
if (true_pixel_aspect_ratio != 1) {
|
||||
int new_width = frame_params.width();
|
||||
int new_height = frame_params.height();
|
||||
|
||||
// Scale the frame in a way that does not reduce the resolution
|
||||
if (frame->sample_aspect_ratio() > 1) {
|
||||
if (frame_params.pixel_aspect_ratio() > 1) {
|
||||
// Make wider
|
||||
new_width = qRound(static_cast<double>(new_width) * frame->sample_aspect_ratio().toDouble());
|
||||
new_width = qRound(static_cast<double>(new_width) * frame_params.pixel_aspect_ratio().toDouble());
|
||||
} else {
|
||||
// Make taller
|
||||
new_height = qRound(static_cast<double>(new_height) / frame->sample_aspect_ratio().toDouble());
|
||||
new_height = qRound(static_cast<double>(new_height) / frame_params.pixel_aspect_ratio().toDouble());
|
||||
}
|
||||
|
||||
frame_params = VideoParams(new_width,
|
||||
new_height,
|
||||
frame_params.format(),
|
||||
frame_params.pixel_aspect_ratio(),
|
||||
frame_params.interlacing(),
|
||||
frame_params.divider());
|
||||
}
|
||||
|
||||
@@ -178,6 +182,8 @@ QVariant OpenGLProxy::FrameToValue(FramePtr frame, StreamPtr stream, const Video
|
||||
VideoParams dest_params(frame_params.width(),
|
||||
frame_params.height(),
|
||||
texture_fmt,
|
||||
frame_params.pixel_aspect_ratio(),
|
||||
frame_params.interlacing(),
|
||||
frame_params.divider());
|
||||
|
||||
// Create destination texture
|
||||
@@ -420,6 +426,8 @@ QVariant OpenGLProxy::RunNodeAccelerated(const Node *node,
|
||||
params.height(),
|
||||
params.time_base(),
|
||||
output_format,
|
||||
params.pixel_aspect_ratio(),
|
||||
params.interlacing(),
|
||||
params.divider());
|
||||
|
||||
int real_iteration_count;
|
||||
|
||||
@@ -127,6 +127,8 @@ void RenderWorker::RenderFrame(RenderTicketPtr ticket, ViewerOutput* viewer, con
|
||||
video_params_.height(),
|
||||
video_params_.time_base(),
|
||||
output_format,
|
||||
video_params_.pixel_aspect_ratio(),
|
||||
video_params_.interlacing(),
|
||||
video_params_.divider()));
|
||||
frame->set_timestamp(time);
|
||||
frame->allocate();
|
||||
@@ -295,6 +297,8 @@ QVariant RenderWorker::ProcessFrameGeneration(const Node* node, const GenerateJo
|
||||
video_params_.height(),
|
||||
video_params_.time_base(),
|
||||
output_fmt,
|
||||
video_params_.pixel_aspect_ratio(),
|
||||
video_params_.interlacing(),
|
||||
video_params_.divider()));
|
||||
frame->allocate();
|
||||
|
||||
@@ -316,6 +320,8 @@ QVariant RenderWorker::GetCachedFrame(const Node* node, const rational& time)
|
||||
f->height() * video_params_.divider(),
|
||||
f->video_params().time_base(),
|
||||
f->video_params().format(),
|
||||
f->video_params().pixel_aspect_ratio(),
|
||||
f->video_params().interlacing(),
|
||||
video_params_.divider()));
|
||||
|
||||
return CachedFrameToTexture(f);
|
||||
|
||||
@@ -263,8 +263,8 @@ FramePtr PixelFormat::ConvertPixelFormat(FramePtr frame, const PixelFormat::Form
|
||||
// Create a destination frame with the same parameters
|
||||
FramePtr converted = Frame::Create();
|
||||
converted->set_video_params(VideoParams(frame->video_params().width(),
|
||||
frame->video_params().height(),
|
||||
dest_format));
|
||||
frame->video_params().height(),
|
||||
dest_format));
|
||||
converted->set_timestamp(frame->timestamp());
|
||||
converted->allocate();
|
||||
|
||||
|
||||
+90
-12
@@ -26,28 +26,70 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
const rational VideoParams::kPixelAspectSquare(1);
|
||||
const rational VideoParams::kPixelAspectNTSCStandard(8, 9);
|
||||
const rational VideoParams::kPixelAspectNTSCWidescreen(32, 27);
|
||||
const rational VideoParams::kPixelAspectPALStandard(16, 15);
|
||||
const rational VideoParams::kPixelAspectPALWidescreen(64, 45);
|
||||
const rational VideoParams::kPixelAspect1080Anamorphic(4, 3);
|
||||
|
||||
const QVector<rational> VideoParams::kSupportedFrameRates = {
|
||||
rational(10, 1), // 10 FPS
|
||||
rational(15, 1), // 15 FPS
|
||||
rational(24000, 1001), // 23.976 FPS
|
||||
rational(24, 1), // 24 FPS
|
||||
rational(25, 1), // 25 FPS
|
||||
rational(30000, 1001), // 29.97 FPS
|
||||
rational(30, 1), // 30 FPS
|
||||
rational(48000, 1001), // 47.952 FPS
|
||||
rational(48, 1), // 48 FPS
|
||||
rational(50, 1), // 50 FPS
|
||||
rational(60000, 1001), // 59.94 FPS
|
||||
rational(60, 1) // 60 FPS
|
||||
};
|
||||
|
||||
const QVector<int> VideoParams::kSupportedDividers = {1, 2, 3, 4, 6, 8, 12, 16};
|
||||
|
||||
const QVector<rational> VideoParams::kStandardPixelAspects = {
|
||||
VideoParams::kPixelAspectSquare,
|
||||
VideoParams::kPixelAspectNTSCStandard,
|
||||
VideoParams::kPixelAspectNTSCWidescreen,
|
||||
VideoParams::kPixelAspectPALStandard,
|
||||
VideoParams::kPixelAspectPALWidescreen,
|
||||
VideoParams::kPixelAspect1080Anamorphic
|
||||
};
|
||||
|
||||
VideoParams::VideoParams() :
|
||||
format_(PixelFormat::PIX_FMT_INVALID)
|
||||
width_(0),
|
||||
height_(0),
|
||||
format_(PixelFormat::PIX_FMT_INVALID),
|
||||
interlacing_(Interlacing::kInterlaceNone)
|
||||
{
|
||||
}
|
||||
|
||||
VideoParams::VideoParams(const int &width, const int &height, const PixelFormat::Format &format, const int& divider) :
|
||||
VideoParams::VideoParams(const int &width, const int &height, const PixelFormat::Format &format, const rational& pixel_aspect_ratio, const Interlacing &interlacing, const int& divider) :
|
||||
width_(width),
|
||||
height_(height),
|
||||
format_(format),
|
||||
pixel_aspect_ratio_(pixel_aspect_ratio),
|
||||
interlacing_(interlacing),
|
||||
divider_(divider)
|
||||
{
|
||||
calculate_effective_size();
|
||||
validate_pixel_aspect_ratio();
|
||||
}
|
||||
|
||||
VideoParams::VideoParams(const int &width, const int &height, const rational &time_base, const PixelFormat::Format &format, const int ÷r) :
|
||||
VideoParams::VideoParams(const int &width, const int &height, const rational &time_base, const PixelFormat::Format &format, const rational& pixel_aspect_ratio, const Interlacing &interlacing, const int ÷r) :
|
||||
width_(width),
|
||||
height_(height),
|
||||
time_base_(time_base),
|
||||
format_(format),
|
||||
pixel_aspect_ratio_(pixel_aspect_ratio),
|
||||
interlacing_(interlacing),
|
||||
divider_(divider)
|
||||
{
|
||||
calculate_effective_size();
|
||||
validate_pixel_aspect_ratio();
|
||||
}
|
||||
|
||||
int VideoParams::generate_auto_divider(qint64 width, qint64 height)
|
||||
@@ -60,16 +102,14 @@ int VideoParams::generate_auto_divider(qint64 width, qint64 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();
|
||||
if (divider <= kSupportedDividers.first()) {
|
||||
return kSupportedDividers.first();
|
||||
} else if (divider >= kSupportedDividers.last()) {
|
||||
return kSupportedDividers.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);
|
||||
for (int i=1; i<kSupportedDividers.size(); i++) {
|
||||
int prev_divider = kSupportedDividers.at(i-1);
|
||||
int next_divider = kSupportedDividers.at(i);
|
||||
|
||||
if (divider >= prev_divider && divider <= next_divider) {
|
||||
double prev_diff = qAbs(prev_divider - divider);
|
||||
@@ -94,6 +134,7 @@ bool VideoParams::operator==(const VideoParams &rhs) const
|
||||
&& height() == rhs.height()
|
||||
&& time_base() == rhs.time_base()
|
||||
&& format() == rhs.format()
|
||||
&& pixel_aspect_ratio() == rhs.pixel_aspect_ratio()
|
||||
&& divider() == rhs.divider();
|
||||
}
|
||||
|
||||
@@ -109,12 +150,49 @@ void VideoParams::calculate_effective_size()
|
||||
effective_height_ = qCeil(height() / divider_ * 0.5) * 2;
|
||||
}
|
||||
|
||||
void VideoParams::validate_pixel_aspect_ratio()
|
||||
{
|
||||
if (pixel_aspect_ratio_.isNull()) {
|
||||
pixel_aspect_ratio_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoParams::is_valid() const
|
||||
{
|
||||
return (width() > 0
|
||||
&& height() > 0
|
||||
&& !pixel_aspect_ratio_.isNull()
|
||||
&& format_ != PixelFormat::PIX_FMT_INVALID
|
||||
&& format_ != PixelFormat::PIX_FMT_COUNT);
|
||||
}
|
||||
|
||||
QString VideoParams::FrameRateToString(const rational &frame_rate)
|
||||
{
|
||||
return QCoreApplication::translate("VideoParams", "%1 FPS").arg(frame_rate.toDouble());
|
||||
}
|
||||
|
||||
QStringList VideoParams::GetStandardPixelAspectRatioNames()
|
||||
{
|
||||
QStringList strings = {
|
||||
QCoreApplication::translate("VideoParams", "Square Pixels (%1)"),
|
||||
QCoreApplication::translate("VideoParams", "NTSC Standard (%1)"),
|
||||
QCoreApplication::translate("VideoParams", "NTSC Widescreen (%1)"),
|
||||
QCoreApplication::translate("VideoParams", "PAL Standard (%1)"),
|
||||
QCoreApplication::translate("VideoParams", "PAL Widescreen (%1)"),
|
||||
QCoreApplication::translate("VideoParams", "HD Anamorphic 1080 (%1)")
|
||||
};
|
||||
|
||||
// Format each
|
||||
for (int i=0; i<strings.size(); i++) {
|
||||
strings.replace(i, FormatPixelAspectRatioString(strings.at(i), kStandardPixelAspects.at(i)));
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
QString VideoParams::FormatPixelAspectRatioString(const QString &format, const rational &ratio)
|
||||
{
|
||||
return format.arg(QString::number(ratio.toDouble(), 'f', 4));
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -29,9 +29,19 @@ OLIVE_NAMESPACE_ENTER
|
||||
|
||||
class VideoParams {
|
||||
public:
|
||||
enum Interlacing {
|
||||
kInterlaceNone,
|
||||
kInterlacedTopFirst,
|
||||
kInterlacedBottomFirst
|
||||
};
|
||||
|
||||
VideoParams();
|
||||
VideoParams(const int& width, const int& height, const PixelFormat::Format& format, const int& divider = 1);
|
||||
VideoParams(const int& width, const int& height, const rational& time_base, const PixelFormat::Format& format, const int& divider = 1);
|
||||
VideoParams(const int& width, const int& height, const PixelFormat::Format& format,
|
||||
const rational& pixel_aspect_ratio = 1,
|
||||
const Interlacing& interlacing = kInterlaceNone, const int& divider = 1);
|
||||
VideoParams(const int& width, const int& height, const rational& time_base,
|
||||
const PixelFormat::Format& format, const rational& pixel_aspect_ratio = 1,
|
||||
const Interlacing& interlacing = kInterlaceNone, const int& divider = 1);
|
||||
|
||||
const int& width() const
|
||||
{
|
||||
@@ -68,6 +78,16 @@ public:
|
||||
return format_;
|
||||
}
|
||||
|
||||
const rational& pixel_aspect_ratio() const
|
||||
{
|
||||
return pixel_aspect_ratio_;
|
||||
}
|
||||
|
||||
Interlacing interlacing() const
|
||||
{
|
||||
return interlacing_;
|
||||
}
|
||||
|
||||
static int generate_auto_divider(qint64 width, qint64 height);
|
||||
|
||||
bool is_valid() const;
|
||||
@@ -75,15 +95,40 @@ public:
|
||||
bool operator==(const VideoParams& rhs) const;
|
||||
bool operator!=(const VideoParams& rhs) const;
|
||||
|
||||
static const rational kPixelAspectSquare;
|
||||
static const rational kPixelAspectNTSCStandard;
|
||||
static const rational kPixelAspectNTSCWidescreen;
|
||||
static const rational kPixelAspectPALStandard;
|
||||
static const rational kPixelAspectPALWidescreen;
|
||||
static const rational kPixelAspect1080Anamorphic;
|
||||
|
||||
static const QVector<rational> kSupportedFrameRates;
|
||||
static const QVector<rational> kStandardPixelAspects;
|
||||
static const QVector<int> kSupportedDividers;
|
||||
|
||||
/**
|
||||
* @brief Convert rational frame rate (i.e. flipped timebase) to a user-friendly string
|
||||
*/
|
||||
static QString FrameRateToString(const rational& frame_rate);
|
||||
|
||||
static QStringList GetStandardPixelAspectRatioNames();
|
||||
static QString FormatPixelAspectRatioString(const QString& format, const rational& ratio);
|
||||
|
||||
private:
|
||||
void calculate_effective_size();
|
||||
|
||||
void validate_pixel_aspect_ratio();
|
||||
|
||||
int width_;
|
||||
int height_;
|
||||
rational time_base_;
|
||||
|
||||
PixelFormat::Format format_;
|
||||
|
||||
rational pixel_aspect_ratio_;
|
||||
|
||||
Interlacing interlacing_;
|
||||
|
||||
int divider_;
|
||||
int effective_width_;
|
||||
int effective_height_;
|
||||
@@ -92,5 +137,6 @@ private:
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::VideoParams)
|
||||
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::VideoParams::Interlacing)
|
||||
|
||||
#endif // VIDEOPARAMS_H
|
||||
|
||||
Reference in New Issue
Block a user