Commit a6e04898 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add normalizers to MLT thumbcreator, fixing Kdeinit crash

CCBUG: 430122
parent 9a1da839
Pipeline #43500 passed with stage
in 10 minutes and 35 seconds
......@@ -24,7 +24,6 @@
#include <QImage>
#include <QVarLengthArray>
#include <QtGlobal>
#include <QDebug>
extern "C" {
......@@ -49,12 +48,10 @@ MltPreview::~MltPreview()
bool MltPreview::create(const QString &path, int width, int height, QImage &img)
{
auto *profile = new Mlt::Profile();
Mlt::Producer *producer = new Mlt::Producer(*profile, path.toUtf8().data());
std::unique_ptr<Mlt::Profile> profile(new Mlt::Profile());
std::shared_ptr<Mlt::Producer>producer(new Mlt::Producer(*profile.get(), path.toUtf8().data()));
if (producer->is_blank()) {
delete producer;
delete profile;
return false;
}
int frame = 75;
......@@ -70,6 +67,24 @@ bool MltPreview::create(const QString &path, int width, int height, QImage &img)
wanted_height = height;
wanted_width = height * ar;
}
// We don't need audio
producer->set("audio_index", -1);
// Add normalizers
Mlt::Filter scaler(*profile.get(), "swscale");
Mlt::Filter padder(*profile.get(), "resize");
Mlt::Filter converter(*profile.get(), "avcolor_space");
if (scaler.is_valid()) {
producer->attach(scaler);
}
if (padder.is_valid()) {
producer->attach(padder);
}
if (converter.is_valid()) {
producer->attach(converter);
}
// img = getFrame(producer, frame, width, height);
while (variance <= 40 && ct < 4) {
......@@ -78,27 +93,23 @@ bool MltPreview::create(const QString &path, int width, int height, QImage &img)
frame += 100 * ct;
ct++;
}
delete producer;
delete profile;
return (!img.isNull());
}
QImage MltPreview::getFrame(Mlt::Producer *producer, int framepos, int width, int height)
QImage MltPreview::getFrame(std::shared_ptr<Mlt::Producer> producer, int framepos, int width, int height)
{
QImage mltImage(width, height, QImage::Format_ARGB32_Premultiplied);
QImage mltImage(width, height, QImage::Format_ARGB32);
if (producer == nullptr) {
return mltImage;
}
producer->seek(framepos);
Mlt::Frame *frame = producer->get_frame();
if (frame == nullptr) {
if (frame == nullptr || !frame->is_valid()) {
return mltImage;
}
mlt_image_format format = mlt_image_rgb24a;
const uchar *imagedata = frame->get_image(format, width, height);
if (imagedata != nullptr) {
memcpy(mltImage.bits(), imagedata, width * height * 4);
......
......@@ -23,7 +23,7 @@
#define MLTPREVIEW_H
#include <kio/thumbcreator.h>
#include <memory>
#include <mlt++/Mlt.h>
#include <QObject>
......@@ -38,7 +38,7 @@ public:
protected:
static uint imageVariance(const QImage &image);
QImage getFrame(Mlt::Producer *producer, int framepos, int width, int height);
QImage getFrame(std::shared_ptr<Mlt::Producer> producer, int framepos, int width, int height);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment