1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 02:32:29 +01:00

Cleanup converting video

This commit is contained in:
Elias 2019-03-14 20:02:44 +01:00
parent fb0ab7aead
commit 5692d6cf6d
7 changed files with 52 additions and 48 deletions

View File

@ -236,7 +236,7 @@ Item {
Connections {
target: screenPlayCreate
onCreateWallpaperStateChanged: {
if (state === Create.State.ConvertingVideoFinished) {
if (state === CreateImportVideo.State.ConvertingVideoFinished) {
btnFinish.state = "enabled"
}
}

View File

@ -92,7 +92,7 @@ Item {
target: screenPlayCreate
onCreateWallpaperStateChanged: {
if (state === Create.State.ConvertingPreviewImageFinished) {
if (state === CreateImportVideo.State.ConvertingPreviewImageFinished) {
imgPreview.source = "file:///"
+ screenPlayCreate.workingDir + "/preview.png"
imgPreview.visible = true
@ -100,30 +100,30 @@ Item {
"Converting Video preview mp4")
}
if (state === Create.State.ConvertingPreviewVideo) {
if (state === CreateImportVideo.State.ConvertingPreviewVideo) {
txtConvert.text = qsTr(
"Generating preview video...")
}
if (state === Create.State.ConvertingPreviewGif) {
if (state === CreateImportVideo.State.ConvertingPreviewGif) {
txtConvert.text = qsTr(
"Generating preview gif...")
}
if (state === Create.State.ConvertingPreviewGifFinished) {
if (state === CreateImportVideo.State.ConvertingPreviewGifFinished) {
imgPreview.source = "file:///"
+ screenPlayCreate.workingDir + "/preview.gif"
imgPreview.visible = true
imgPreview.playing = true
}
if (state === Create.State.ConvertingAudio) {
if (state === CreateImportVideo.State.ConvertingAudio) {
txtConvert.text = qsTr("Converting Audio...")
}
if (state === Create.State.ConvertingVideo) {
if (state === CreateImportVideo.State.ConvertingVideo) {
txtConvert.text = qsTr("Converting Video...")
}
if (state === Create.State.Finished) {
if (state === CreateImportVideo.State.Finished) {
imgSuccess.source = "file:///"
+ screenPlayCreate.workingDir + "/preview.gif"
}
@ -287,7 +287,7 @@ Item {
Connections {
target: screenPlayCreate
onCreateWallpaperStateChanged: {
if (state === Create.State.ConvertingVideoFinished) {
if (state === CreateImportVideo.State.ConvertingVideoFinished) {
btnFinish.state = "enabled"
}
}

View File

@ -4,6 +4,7 @@ import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.3
import Qt.labs.platform 1.0
import QtQuick.Layouts 1.3
import net.aimber.create 1.0
Item {
@ -34,10 +35,10 @@ Item {
target: screenPlayCreate
onCreateWallpaperStateChanged: {
if (state === Create.State.ConvertingPreviewGifError
|| state === Create.State.ConvertingPreviewVideoError
|| state === Create.State.ConvertingPreviewImageError
|| state === Create.State.AnalyseVideoError) {
if (state === CreateImportVideo.State.ConvertingPreviewGifError
|| state === CreateImportVideo.State.ConvertingPreviewVideoError
|| state === CreateImportVideo.State.ConvertingPreviewImageError
|| state === CreateImportVideo.State.AnalyseVideoError) {
createNew.state = "error"
}
}

View File

@ -9,6 +9,7 @@ Create::Create(Settings* st, QMLUtilities* util, QObject* parent)
qRegisterMetaType<CreateImportVideo::State>();
qmlRegisterType<Create>("net.aimber.create", 1, 0, "Create");
qmlRegisterType<CreateImportVideo>("net.aimber.create", 1, 0, "Create");
}
void Create::copyProject(QString relativeProjectPath, QString toPath)
@ -69,31 +70,31 @@ void Create::createWallpaperStart(QString videoPath)
m_createWallpaperData.exportPath = dir.path() + "/" + folderName;
setWorkingDir(m_createWallpaperData.exportPath);
auto* thread = new QThread;
m_createImportVideoThread = new QThread;
m_createImportVideo = new CreateImportVideo(videoPath, m_createWallpaperData.exportPath);
connect(m_createImportVideo, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
connect(thread, &QThread::started, m_createImportVideo, &CreateImportVideo::process);
connect(m_createImportVideo, &CreateImportVideo::finished, thread, &QThread::quit);
//connect(m_createImportVideo, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
connect(m_createImportVideoThread, &QThread::started, m_createImportVideo, &CreateImportVideo::process);
connect(m_createImportVideo, &CreateImportVideo::finished, m_createImportVideoThread, &QThread::quit);
connect(m_createImportVideo, &CreateImportVideo::finished, m_createImportVideo, &QObject::deleteLater);
connect(thread, &QThread::finished, thread, &QObject::deleteLater);
m_createImportVideo->moveToThread(thread);
thread->start();
connect(m_createImportVideoThread, &QThread::finished, m_createImportVideoThread, &QObject::deleteLater);
connect(m_createImportVideoThread, &QThread::destroyed, this, [this]() {
QDir exportPath(m_createWallpaperData.exportPath);
if (exportPath.exists()) {
if (!exportPath.removeRecursively()) {
emit createWallpaperStateChanged(CreateImportVideo::State::AbortCleanupError);
qWarning() << "Could not delete temp exportPath: " << exportPath;
} else {
qDebug() << "cleanup " << m_createWallpaperData.exportPath;
}
}
});
m_createImportVideo->moveToThread(m_createImportVideoThread);
m_createImportVideoThread->start();
}
void Create::abortAndCleanup()
{
emit abortCreateWallpaper();
QDir exportPath(m_createWallpaperData.exportPath);
if (exportPath.exists()) {
if (!exportPath.removeRecursively()) {
emit createWallpaperStateChanged(CreateImportVideo::State::AbortCleanupError);
qWarning() << "Could not delete temp exportPath: " << exportPath;
} else {
qDebug() << "cleanup " << m_createWallpaperData.exportPath;
}
}
m_createImportVideoThread->requestInterruption();
}

View File

@ -35,8 +35,6 @@ struct CreateWallpaperData {
int framerate = 0;
};
class Create : public QObject {
Q_OBJECT
public:
@ -90,11 +88,12 @@ public slots:
}
private:
CreateImportVideo* m_createImportVideo;
Settings* m_settings;
QThread* m_createImportVideoThread;
QMLUtilities* m_utils;
CreateWallpaperData m_createWallpaperData;
QString m_workingDir;
float m_progress = 0.0f;
};

View File

@ -1,5 +1,10 @@
#include "createimportvideo.h"
CreateImportVideo::CreateImportVideo(QObject* parent)
: QObject(parent)
{
}
CreateImportVideo::CreateImportVideo(QString videoPath, QString exportPath, QObject* parent)
: QObject(parent)
{
@ -140,7 +145,7 @@ bool CreateImportVideo::createWallpaperVideoPreview()
#endif
emit createWallpaperStateChanged(CreateImportVideo::State::ConvertingPreviewVideo);
//connect(this, &Create::abortCreateWallpaper, proConvertPreviewWebM.data(), &QProcess::kill);
proConvertPreviewWebM.data()->start();
while (!proConvertPreviewWebM.data()->waitForFinished(100)) //Wake up every 100ms and check if we must exit
{
@ -154,7 +159,7 @@ bool CreateImportVideo::createWallpaperVideoPreview()
}
QCoreApplication::processEvents();
}
//disconnect(this, &Create::abortCreateWallpaper, proConvertPreviewWebM.data(), &QProcess::kill);
QString tmpErr = proConvertPreviewWebM.data()->readAllStandardError();
if (!tmpErr.isEmpty()) {
QFile previewVideo(m_exportPath + "/preview.webm");
@ -195,7 +200,7 @@ bool CreateImportVideo::createWallpaperGifPreview()
#ifdef Q_OS_MACOS
proConvertGif.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg");
#endif
//connect(this, &Create::abortCreateWallpaper, proConvertGif.data(), &QProcess::kill);
proConvertGif.data()->start();
while (!proConvertGif.data()->waitForFinished(100)) //Wake up every 100ms and check if we must exit
{
@ -209,7 +214,7 @@ bool CreateImportVideo::createWallpaperGifPreview()
}
QCoreApplication::processEvents();
}
//disconnect(this, &Create::abortCreateWallpaper, proConvertGif.data(), &QProcess::kill);
QString tmpErrGif = proConvertGif.data()->readAllStandardError();
if (!tmpErrGif.isEmpty()) {
QFile previewGif(m_exportPath + "/preview.gif");
@ -311,7 +316,6 @@ bool CreateImportVideo::extractWallpaperAudio()
pro.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg");
#endif
//connect(this, &Create::abortCreateWallpaper, proConvertAudio.data(), &QProcess::kill);
proConvertAudio.data()->start(QIODevice::ReadOnly);
while (!proConvertAudio.data()->waitForFinished(100)) //Wake up every 100ms and check if we must exit
{
@ -325,7 +329,6 @@ bool CreateImportVideo::extractWallpaperAudio()
}
QCoreApplication::processEvents();
}
//disconnect(this, &Create::abortCreateWallpaper, proConvertAudio.data(), &QProcess::kill);
QString tmpErrImg = proConvertAudio.data()->readAllStandardError();
if (!tmpErrImg.isEmpty()) {

View File

@ -1,5 +1,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
@ -8,16 +10,15 @@
#include <QJsonObject>
#include <QJsonParseError>
#include <QObject>
#include <QString>
#include <QDebug>
#include <QThread>
#include <QProcess>
#include <QApplication>
#include <QString>
#include <QThread>
#include <QtMath>
class CreateImportVideo : public QObject {
Q_OBJECT
public:
CreateImportVideo(QObject* parent = nullptr);
explicit CreateImportVideo(QString videoPath, QString exportPath, QObject* parent = nullptr);
enum class State {
@ -58,7 +59,6 @@ public slots:
void process();
void requestInterruption()
{
}
bool createWallpaperInfo();