1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2017-05-25
* Description : a tool to generate video slideshow from images.
*
* SPDX-FileCopyrightText: 2017-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "vidslidethread.h"
// Qt include
#include <QDir>
#include <QDateTime>
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "digikam_debug.h"
#include "digikam_config.h"
namespace Digikam
{
VidSlideThread::VidSlideThread(QObject* const parent)
: ActionThreadBase(parent)
{
setObjectName(QLatin1String("VidSlideThread"));
}
VidSlideThread::~VidSlideThread()
{
cancel();
wait();
if (m_settings && QDir().exists(m_settings->tempDir))
{
QDir(m_settings->tempDir).removeRecursively();
}
}
void VidSlideThread::prepareFrames(VidSlideSettings* const settings)
{
m_settings = settings;
m_settings->tempDir = m_settings->outputDir + QLatin1String("/.") +
QString::number(QDateTime::currentSecsSinceEpoch()) +
QLatin1Char('/');
if (!QDir().mkpath(m_settings->tempDir))
{
qCWarning(DIGIKAM_GENERAL_LOG) << "Cannot create temporary directory:" << m_settings->tempDir;
Q_EMIT signalMessage(i18n("Error while creating temporary directory %1!", m_settings->tempDir), true);
return;
}
ActionJobCollection collection;
VidSlideTask* const t = new VidSlideTask(settings);<--- Variable 't' can be declared as pointer to const
connect(t, SIGNAL(signalProgress(int)),
this, SIGNAL(signalProgress(int)));
connect(t, SIGNAL(signalMessage(QString,bool)),
this, SIGNAL(signalMessage(QString,bool)));
connect(t, SIGNAL(signalDone(bool)),
this, SLOT(slotEncodeFrames(bool)));
collection.insert(t, 0);
appendJobs(collection);
}
void VidSlideThread::slotEncodeFrames(bool prepareDone)
{
if (!prepareDone)
{
Q_EMIT signalDone(false);
return;
}
Q_EMIT signalMessage(i18n("Encoding frames..."), false);
if (m_encoder)
{
delete m_encoder;
}
m_encoder = new FFmpegLauncher(this);
m_encoder->setSettings(m_settings);
connect(m_encoder, &ProcessLauncher::signalComplete,
this, &VidSlideThread::slotEncodeDone,
Qt::DirectConnection);
m_encoder->encodeFrames();
}
void VidSlideThread::slotEncodeDone(bool success, int exitCode)
{
bool b = false;
if (!success || (exitCode != 0))
{
qCDebug(DIGIKAM_GENERAL_LOG) << "Cannot generate output video" << m_settings->outputFile;
}
else
{
qCDebug(DIGIKAM_GENERAL_LOG) << "Output video is" << m_settings->outputFile;
b = true;
}
if (b)
{
if (QDir().exists(m_settings->tempDir))
{
QDir(m_settings->tempDir).removeRecursively();
}
Q_EMIT signalMessage(i18n("Encoding done."), false);
}
else
{
Q_EMIT signalMessage(i18n("Error while encoding frames!"), true);
}
Q_EMIT signalDone(b);
}
QString VidSlideThread::encodingTraces() const
{
if (m_encoder)
{
return m_encoder->output();
}
return QString();
}
} // namespace Digikam
#include "moc_vidslidethread.cpp"
|