Small cleanup of bin preview thumbnails job, automatically fetch 10 thumbs at...

Small cleanup of bin preview thumbnails job, automatically fetch 10 thumbs at insert to allow quick preview
and fetch another 40 when seeking is requested
parent c049c15c
Pipeline #6011 passed with stage
in 27 minutes and 43 seconds
......@@ -3192,7 +3192,7 @@ void Bin::showBinFrame(QModelIndex ix, int frame)
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
if (item && item->itemType() == AbstractProjectItem::ClipItem) {
auto clip = std::static_pointer_cast<ProjectClip>(item);
if (clip && (clip->clipType() == ClipType::AV || clip->clipType() == ClipType::Video)) {
if (clip && (clip->clipType() == ClipType::AV || clip->clipType() == ClipType::Video || clip->clipType() == ClipType::Playlist)) {
clip->getThumbFromPercent(frame);
}
}
......
......@@ -1400,10 +1400,10 @@ void ProjectClip::updateZones()
void ProjectClip::getThumbFromPercent(int percent)
{
// extract a maximum of 25 frames for bin preview
percent /= 4;
// extract a maximum of 50 frames for bin preview
percent += percent%2;
int duration = getFramePlaytime();
int framePos = duration * percent / 25;
int framePos = duration * percent / 100;
if (ThumbnailCache::get()->hasThumbnail(m_binId, framePos)) {
setThumbnail(ThumbnailCache::get()->getThumbnail(m_binId, framePos));
} else {
......@@ -1411,11 +1411,7 @@ void ProjectClip::getThumbFromPercent(int percent)
int id;
if (pCore->jobManager()->hasPendingJob(m_binId, AbstractClipJob::CACHEJOB, &id)) {
} else {
std::set<int>frames;
for (int i = 1; i <= 100; ++i) {
frames.insert(duration * i / 25);
}
pCore->jobManager()->startJob<CacheJob>({m_binId}, -1, QString(), 150, frames);
pCore->jobManager()->startJob<CacheJob>({m_binId}, -1, QString(), 150, 50);
}
}
}
......@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "jobs/jobmanager.h"
#include "jobs/loadjob.hpp"
#include "jobs/thumbjob.hpp"
#include "jobs/cachejob.hpp"
#include "kdenlivesettings.h"
#include "macros.hpp"
#include "profiles/profilemodel.hpp"
......@@ -648,7 +649,8 @@ bool ProjectItemModel::requestAddBinClip(QString &id, const QDomElement &descrip
qDebug() << "/////////// added " << res;
if (res) {
int loadJob = pCore->jobManager()->startJob<LoadJob>({id}, -1, QString(), description, std::bind(readyCallBack, id));
pCore->jobManager()->startJob<ThumbJob>({id}, loadJob, QString(), 150, 0, true);
int thumbJob = pCore->jobManager()->startJob<ThumbJob>({id}, loadJob, QString(), 150, 0, true);
pCore->jobManager()->startJob<CacheJob>({id}, thumbJob, QString(), 150);
pCore->jobManager()->startJob<AudioThumbJob>({id}, loadJob, QString());
}
return res;
......
......@@ -667,8 +667,8 @@ Mlt::Profile *Core::thumbProfile()
QMutexLocker lck(&m_thumbProfileMutex);
if (!m_thumbProfile) {
m_thumbProfile = std::make_unique<Mlt::Profile>(m_currentProfile.toStdString().c_str());
m_thumbProfile->set_height(200);
int width = 200 * m_thumbProfile->dar();
m_thumbProfile->set_height(144);
int width = 144 * m_thumbProfile->dar() + 0.5;
if (width % 8 > 0) {
width += 8 - width % 8;
}
......
......@@ -32,12 +32,14 @@
#include <QScopedPointer>
#include <mlt++/MltProducer.h>
CacheJob::CacheJob(const QString &binId, int imageHeight, std::set<int> frames)
#include <set>
CacheJob::CacheJob(const QString &binId, int imageHeight, int thumbsCount)
: AbstractClipJob(CACHEJOB, binId)
, m_frames(frames)
, m_fullWidth(imageHeight * pCore->getCurrentDar() + 0.5)
, m_imageHeight(imageHeight)
, m_done(false)
, m_thumbsCount(thumbsCount)
{
if (m_fullWidth % 8 > 0) {
......@@ -45,7 +47,7 @@ CacheJob::CacheJob(const QString &binId, int imageHeight, std::set<int> frames)
}
m_imageHeight += m_imageHeight % 2;
auto item = pCore->projectItemModel()->getItemByBinId(binId);
Q_ASSERT(item->itemType() == AbstractProjectItem::ClipItem);
Q_ASSERT(item != nullptr && item->itemType() == AbstractProjectItem::ClipItem);
}
const QString CacheJob::getDescription() const
......@@ -57,8 +59,9 @@ bool CacheJob::startJob()
{
// We reload here, because things may have changed since creation of this job
m_binClip = pCore->projectItemModel()->getClipByBinID(m_clipId);
if (m_binClip->clipType() != ClipType::Video && m_binClip->clipType() != ClipType::AV) {
if (m_binClip->clipType() != ClipType::Video && m_binClip->clipType() != ClipType::AV && m_binClip->clipType() != ClipType::Playlist) {
// Don't create thumbnail for audio clips
qDebug()<<"!!!!!!!!!!!\n\n WRONG CLIP TYPE\n\n!!!!!!!!!!";
m_done = false;
return true;
}
......@@ -67,7 +70,16 @@ bool CacheJob::startJob()
qDebug() << "********\nCOULD NOT READ THUMB PRODUCER\n********";
return false;
}
for (int i : m_frames) {
int duration = m_binClip->frameDuration();
std::set<int> frames;
for (int i = 1; i <= m_thumbsCount; ++i) {
frames.insert(duration * i / m_thumbsCount);
}
int size = frames.size();
int count = 0;
for (int i : frames) {
emit jobProgress(100 * count / size);
count++;
if (ThumbnailCache::get()->hasThumbnail(m_binClip->clipId(), i)) {
continue;
}
......
......@@ -24,7 +24,6 @@
#include "abstractclipjob.h"
#include <memory>
#include <set>
/* @brief This class represents the job that corresponds to computing the thumb of a clip
*/
......@@ -43,7 +42,7 @@ public:
@param frameNumber is the frame to extract. Leave to -1 for default
@param persistent: if true, we will use the persistent cache (for query and saving)
*/
CacheJob(const QString &binId, int imageHeight, std::set<int> frames);
CacheJob(const QString &binId, int imageHeight, int thumbsCount = 10);
const QString getDescription() const override;
......@@ -54,7 +53,6 @@ public:
bool commitResult(Fun &undo, Fun &redo) override;
private:
std::set<int> m_frames;
int m_fullWidth;
int m_imageHeight;
......@@ -62,6 +60,7 @@ private:
std::shared_ptr<Mlt::Producer> m_prod;
bool m_done{false};
int m_thumbsCount;
bool m_inCache{false};
bool m_subClip{false}; // true if we operate on a subclip
};
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