diff --git a/autotests/ffmpegextractortest.cpp b/autotests/ffmpegextractortest.cpp --- a/autotests/ffmpegextractortest.cpp +++ b/autotests/ffmpegextractortest.cpp @@ -50,6 +50,7 @@ QCOMPARE(result.properties().value(Width).toInt(), 1280); QCOMPARE(result.properties().value(Height).toInt(), 720); QVERIFY(abs(result.properties().value(FrameRate).toDouble() - 23.976) < 1e-4); + QVERIFY(abs(result.properties().value(AspectRatio).toDouble() - 1.77778) < 1e-4); } QTEST_GUILESS_MAIN(ffmpegExtractorTest) diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -92,6 +92,9 @@ PropertyInfo framerate(Property::FrameRate); QCOMPARE(framerate.formatAsDisplayString(QVariant(23)), QStringLiteral("23 fps")); QCOMPARE(framerate.formatAsDisplayString(QVariant(23.976)), QStringLiteral("23.98 fps")); + + PropertyInfo aspectRatio(Property::AspectRatio); + QCOMPARE(aspectRatio.formatAsDisplayString(QVariant(1.77778)), QStringLiteral("1.78:1")); } QTEST_GUILESS_MAIN(PropertyInfoTest) diff --git a/src/extractors/ffmpegextractor.cpp b/src/extractors/ffmpegextractor.cpp --- a/src/extractors/ffmpegextractor.cpp +++ b/src/extractors/ffmpegextractor.cpp @@ -106,11 +106,17 @@ result->add(Property::Width, codec->width); result->add(Property::Height, codec->height); - int aspectRatio = codec->sample_aspect_ratio.num; - if (codec->sample_aspect_ratio.den) - aspectRatio /= codec->sample_aspect_ratio.den; - if (aspectRatio) - result->add(Property::AspectRatio, aspectRatio); + AVRational avSampleAspectRatio = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL); + AVRational avDisplayAspectRatio; + av_reduce(&avDisplayAspectRatio.num, &avDisplayAspectRatio.den, + codec->width * avSampleAspectRatio.num, + codec->height * avSampleAspectRatio.den, + 1024*1024); + double displayAspectRatio = avDisplayAspectRatio.num; + if (avDisplayAspectRatio.den) + displayAspectRatio /= avDisplayAspectRatio.den; + if (displayAspectRatio) + result->add(Property::AspectRatio, displayAspectRatio); AVRational avFrameRate = av_guess_frame_rate(fmt_ctx, stream, NULL); double frameRate = avFrameRate.num; diff --git a/src/formatstrings.cpp b/src/formatstrings.cpp --- a/src/formatstrings.cpp +++ b/src/formatstrings.cpp @@ -151,3 +151,8 @@ { return QString(QString::number(round(value.toDouble() * 100) / 100) + i18nc("Symbol of frames per second, with space", " fps")); } + +QString FormatStrings::formatAspectRatio(const QVariant& value) +{ + return QString(QString::number(round(value.toDouble() * 100) / 100) + QStringLiteral(":1")); +} diff --git a/src/formatstrings_p.h b/src/formatstrings_p.h --- a/src/formatstrings_p.h +++ b/src/formatstrings_p.h @@ -51,6 +51,8 @@ static QString formatAsFrameRate(const QVariant& value); + static QString formatAspectRatio(const QVariant& value); + }; } diff --git a/src/propertyinfo.cpp b/src/propertyinfo.cpp --- a/src/propertyinfo.cpp +++ b/src/propertyinfo.cpp @@ -70,7 +70,8 @@ case Property::AspectRatio: d->name = QStringLiteral("aspectRatio"); d->displayName = i18nc("@label", "Aspect Ratio"); - d->valueType = QVariant::Int; + d->valueType = QVariant::Double; + d->formatAsString = &FormatStrings::formatAspectRatio; break; case Property::Author: