Commit d9a795f3 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added code for auto-detecting the ffmpeg presence

And crying to the user if not ;)
parent 36430e8f
......@@ -1682,3 +1682,13 @@ void KisConfig::setStabilizerSampleSize(int value)
{
m_cfg.writeEntry("stabilizerSampleSize", value);
}
QString KisConfig::customFFMpegPath(bool defaultValue) const
{
return defaultValue ? QString() : m_cfg.readEntry("ffmpegExecutablePath", QString());
}
void KisConfig::setCustomFFMpegPath(const QString &value) const
{
m_cfg.writeEntry("ffmpegExecutablePath", value);
}
......@@ -476,6 +476,9 @@ public:
int stabilizerSampleSize(bool defaultValue = false) const;
void setStabilizerSampleSize(int value);
QString customFFMpegPath(bool defaultValue = false) const;
void setCustomFFMpegPath(const QString &value) const;
template<class T>
void writeEntry(const QString& name, const T& value) {
......
......@@ -31,6 +31,7 @@
#include <KisFilterChain.h>
#include <KoColorSpaceConstants.h>
#include "KisPart.h"
#include <KisDocument.h>
#include <kis_image.h>
#include <kis_group_layer.h>
......@@ -55,7 +56,7 @@ KisVideoExport::~KisVideoExport()
KisImportExportFilter::ConversionStatus KisVideoExport::convert(const QByteArray& from, const QByteArray& to)
{
dbgFile << "Video export! From:" << from << ", To:" << to << "";
Q_UNUSED(to);
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
......@@ -104,6 +105,22 @@ KisImportExportFilter::ConversionStatus KisVideoExport::convert(const QByteArray
}
VideoSaver kpc(input, getBatchMode());
if (!kpc.hasFFMpeg()) {
const QString warningMessage =
i18n("Couldn not find \'ffmpeg\' binary. Saving to video formats is impossible.");
if (askForOptions) {
QMessageBox::critical(KisPart::instance()->currentMainwindow(),
i18n("Video Export Error"),
warningMessage);
} else {
qWarning() << "WARNING:" << warningMessage;
}
return KisImportExportFilter::UsageError;
}
KisImageBuilder_Result res = kpc.encode(filename, additionalOptionsList);
if (res == KisImageBuilder_RESULT_OK) {
......
......@@ -42,8 +42,12 @@ void KisVideoPluginTest::testFiles()
VideoSaver saver(doc, false);
//saver.encode("testfile.gif");
saver.encode("testfile.ogg");
KisImageBuilder_Result result =
//saver.encode("testfile.gif");
saver.encode("testfile.ogg");
QCOMPARE(result, KisImageBuilder_RESULT_OK);
}
QTEST_MAIN(KisVideoPluginTest)
......@@ -27,11 +27,14 @@
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorModelStandardIds.h>
#include <KoResourcePaths.h>
#include <kis_image.h>
#include <kis_image_animation_interface.h>
#include <kis_time_range.h>
#include "kis_config.h"
#include "kis_animation_exporter.h"
#include <QFileSystemWatcher>
......@@ -97,8 +100,9 @@ private:
class KisFFMpegRunner
{
public:
KisFFMpegRunner()
: m_cancelled(false) {}
KisFFMpegRunner(const QString &ffmpegPath)
: m_cancelled(false),
m_ffmpegPath(ffmpegPath) {}
public:
KisImageBuilder_Result runFFMpeg(const QStringList &specialArgs,
const QString &actionName,
......@@ -116,7 +120,7 @@ public:
<< specialArgs;
m_cancelled = false;
m_process.start("ffmpeg", args);
m_process.start(m_ffmpegPath, args);
return waitForFFMpegProcess(actionName, progressFile, m_process, totalFrames);
}
......@@ -167,6 +171,7 @@ private:
private:
QProcess m_process;
bool m_cancelled;
QString m_ffmpegPath;
};
......@@ -174,8 +179,10 @@ VideoSaver::VideoSaver(KisDocument *doc, bool batchMode)
: m_image(doc->image())
, m_doc(doc)
, m_batchMode(batchMode)
, m_runner(new KisFFMpegRunner)
, m_ffmpegPath(findFFMpeg())
, m_runner(new KisFFMpegRunner(m_ffmpegPath))
{
}
VideoSaver::~VideoSaver()
......@@ -187,8 +194,49 @@ KisImageSP VideoSaver::image()
return m_image;
}
bool VideoSaver::hasFFMpeg() const
{
return !m_ffmpegPath.isEmpty();
}
QString VideoSaver::findFFMpeg()
{
QString result;
QStringList proposedPaths;
QString customPath = KisConfig().customFFMpegPath();
proposedPaths << customPath;
proposedPaths << customPath + QDir::separator() + "ffmpeg";
proposedPaths << "ffmpeg";
proposedPaths << KoResourcePaths::getApplicationRoot() +
QDir::separator() + "bin" + QDir::separator() + "ffmpeg";
Q_FOREACH (const QString &path, proposedPaths) {
if (path.isEmpty()) continue;
QProcess testProcess;
testProcess.start(path, QStringList() << "-version");
testProcess.waitForFinished(1000);
const bool successfulStart =
testProcess.state() == QProcess::NotRunning &&
testProcess.error() == QProcess::UnknownError;
if (successfulStart) {
result = path;
break;
}
}
return result;
}
KisImageBuilder_Result VideoSaver::encode(const QString &filename, const QStringList &additionalOptionsList)
{
if (m_ffmpegPath.isEmpty()) return KisImageBuilder_RESULT_FAILURE;
KisImageBuilder_Result retval= KisImageBuilder_RESULT_OK;
KisImageAnimationInterface *animation = m_image->animationInterface();
......
......@@ -43,13 +43,19 @@ public:
KisImageSP image();
KisImageBuilder_Result encode(const QString &filename, const QStringList &additionalOptionsList = QStringList());
bool hasFFMpeg() const;
private Q_SLOTS:
void cancel();
private:
static QString findFFMpeg();
private:
KisImageSP m_image;
KisDocument* m_doc;
bool m_batchMode;
QString m_ffmpegPath;
QScopedPointer<KisFFMpegRunner> m_runner;
};
......
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