use sample aspect ratio correctly
This commit is contained in:
@@ -143,18 +143,6 @@ bool FFmpegDecoder::Open()
|
||||
// We should never get here, but just in case...
|
||||
qFatal("Invalid output format");
|
||||
}
|
||||
|
||||
// Determine sample aspect ratio
|
||||
AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx_, avstream_, nullptr);
|
||||
|
||||
// Use it to determine the display aspect ratio
|
||||
// I'll be honest, I'm not entirely sure how this works or what it does. This code is the DAR code from ffprobe
|
||||
// and seems to retrieve the DAR accurately.
|
||||
av_reduce(&display_aspect_ratio_.num,
|
||||
&display_aspect_ratio_.den,
|
||||
avstream_->codecpar->width * sar.num,
|
||||
avstream_->codecpar->height * sar.den,
|
||||
1024*1024);
|
||||
}
|
||||
|
||||
// All allocation succeeded so we set the state to open
|
||||
@@ -192,7 +180,7 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode)
|
||||
frame_container->set_height(avstream_->codecpar->height);
|
||||
frame_container->set_format(native_pix_fmt_);
|
||||
frame_container->set_timestamp(Timecode::timestamp_to_time(target_ts, avstream_->time_base));
|
||||
frame_container->set_aspect_ratio(display_aspect_ratio_);
|
||||
frame_container->set_sample_aspect_ratio(av_guess_sample_aspect_ratio(fmt_ctx_, avstream_, nullptr));
|
||||
frame_container->allocate();
|
||||
|
||||
memcpy(frame_container->data(), frame_loader.constData(), frame_loader.size());
|
||||
|
||||
@@ -147,8 +147,6 @@ private:
|
||||
AVPixelFormat ideal_pix_fmt_;
|
||||
PixelFormat::Format native_pix_fmt_;
|
||||
|
||||
AVRational display_aspect_ratio_;
|
||||
|
||||
QVector<int64_t> frame_index_;
|
||||
|
||||
};
|
||||
|
||||
+5
-5
@@ -31,7 +31,7 @@ Frame::Frame() :
|
||||
format_(PixelFormat::PIX_FMT_INVALID),
|
||||
sample_count_(0),
|
||||
timestamp_(0),
|
||||
aspect_ratio_(1)
|
||||
sample_aspect_ratio_(1)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,14 +60,14 @@ void Frame::set_height(const int &height)
|
||||
height_ = height;
|
||||
}
|
||||
|
||||
const rational &Frame::aspect_ratio() const
|
||||
const rational &Frame::sample_aspect_ratio() const
|
||||
{
|
||||
return aspect_ratio_;
|
||||
return sample_aspect_ratio_;
|
||||
}
|
||||
|
||||
void Frame::set_aspect_ratio(const rational &aspect_ratio)
|
||||
void Frame::set_sample_aspect_ratio(const rational &aspect_ratio)
|
||||
{
|
||||
aspect_ratio_ = aspect_ratio;
|
||||
sample_aspect_ratio_ = aspect_ratio;
|
||||
}
|
||||
|
||||
const AudioRenderingParams &Frame::audio_params() const
|
||||
|
||||
+3
-3
@@ -53,8 +53,8 @@ public:
|
||||
const int& height() const;
|
||||
void set_height(const int& height);
|
||||
|
||||
const rational& aspect_ratio() const;
|
||||
void set_aspect_ratio(const rational& aspect_ratio);
|
||||
const rational& sample_aspect_ratio() const;
|
||||
void set_sample_aspect_ratio(const rational& sample_aspect_ratio);
|
||||
|
||||
const AudioRenderingParams& audio_params() const;
|
||||
void set_audio_params(const AudioRenderingParams& params);
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
|
||||
rational timestamp_;
|
||||
|
||||
rational aspect_ratio_;
|
||||
rational sample_aspect_ratio_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -102,21 +102,17 @@ void OpenGLWorker::FrameToValue(StreamPtr stream, FramePtr frame, NodeValueTable
|
||||
}
|
||||
|
||||
// Check frame aspect ratio
|
||||
rational literal_ar(frame->width(), frame->height());
|
||||
|
||||
if (literal_ar != frame->aspect_ratio()) {
|
||||
qDebug() << "NON EQUAL ASPECT RATIO, adjusting!";
|
||||
|
||||
if (frame->sample_aspect_ratio() != 1) {
|
||||
int new_width = frame->width();
|
||||
int new_height = frame->height();
|
||||
|
||||
// Scale the frame in a way that does not reduce the resolution
|
||||
if (frame->aspect_ratio() > literal_ar) {
|
||||
if (frame->sample_aspect_ratio() > 1) {
|
||||
// Make wider
|
||||
new_width = qRound(static_cast<double>(new_width) * frame->aspect_ratio().toDouble() / literal_ar.toDouble());
|
||||
new_width = qRound(static_cast<double>(new_width) * frame->sample_aspect_ratio().toDouble());
|
||||
} else {
|
||||
// Make taller
|
||||
new_height = qRound(static_cast<double>(new_height) * literal_ar.toDouble() / frame->aspect_ratio().toDouble());
|
||||
new_height = qRound(static_cast<double>(new_height) / frame->sample_aspect_ratio().toDouble());
|
||||
}
|
||||
|
||||
footage_params = VideoRenderingParams(new_width,
|
||||
|
||||
Reference in New Issue
Block a user