mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-18 16:32:33 +02:00
Replace all enums
This commit is contained in:
parent
6943ea0ed7
commit
d371f4b45e
@ -5,14 +5,15 @@ import QtQuick.Controls.Material 2.2
|
|||||||
import QtGraphicalEffects 1.0
|
import QtGraphicalEffects 1.0
|
||||||
import QtQuick.Particles 2.0
|
import QtQuick.Particles 2.0
|
||||||
|
|
||||||
//Enums
|
import net.aimber.create 1.0
|
||||||
import LocalWorkshopCreationStatus 1.0
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: create
|
id: create
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
state: "out"
|
state: "out"
|
||||||
Component.onCompleted: create.state = "create"
|
Component.onCompleted: {
|
||||||
|
create.state = "create"
|
||||||
|
}
|
||||||
property url activeVideoFile: ""
|
property url activeVideoFile: ""
|
||||||
property url activeFolder: ""
|
property url activeFolder: ""
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ Rectangle {
|
|||||||
Connections {
|
Connections {
|
||||||
target: screenPlayCreate
|
target: screenPlayCreate
|
||||||
onLocalWorkshopCreationStatusChanged: {
|
onLocalWorkshopCreationStatusChanged: {
|
||||||
if (status === LocalWorkshopCreationStatus.Started) {
|
if (status === Create.State.Started) {
|
||||||
loader.setSource("CreateImportStatus.qml")
|
loader.setSource("CreateImportStatus.qml")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,18 @@
|
|||||||
Create::Create(Settings* st, QMLUtilities* util, QObject* parent)
|
Create::Create(Settings* st, QMLUtilities* util, QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_settings = st;
|
m_settings = st;
|
||||||
m_utils = util;
|
m_utils = util;
|
||||||
qRegisterMetaType<LocalWorkshopCreationStatus::Value>();
|
qmlRegisterType<Create>("net.aimber.create", 1, 0, "Create");
|
||||||
qmlRegisterUncreatableMetaObject(LocalWorkshopCreationStatus::staticMetaObject, "LocalWorkshopCreationStatus", 1, 0, "LocalWorkshopCreationStatus", "Error: only enums");
|
}
|
||||||
|
|
||||||
|
Create::Create()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Create::~Create()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create::copyProject(QString relativeProjectPath, QString toPath)
|
void Create::copyProject(QString relativeProjectPath, QString toPath)
|
||||||
@ -48,8 +56,7 @@ bool Create::copyRecursively(const QString& srcFilePath, const QString& tgtFileP
|
|||||||
void Create::importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration)
|
void Create::importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration)
|
||||||
{
|
{
|
||||||
QtConcurrent::run([=]() {
|
QtConcurrent::run([=]() {
|
||||||
|
emit localWorkshopCreationStatusChanged(State::Started);
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::Started);
|
|
||||||
|
|
||||||
QString fromVideoPath = QString(videoPath.toString()).replace("file:///", "");
|
QString fromVideoPath = QString(videoPath.toString()).replace("file:///", "");
|
||||||
QString fromImagePath = QString(previewPath.toString()).replace("file:///", "");
|
QString fromImagePath = QString(previewPath.toString()).replace("file:///", "");
|
||||||
@ -59,7 +66,7 @@ void Create::importVideo(QString title, QUrl videoPath, QUrl previewPath, int vi
|
|||||||
|
|
||||||
if (QDir(toPath).exists()) {
|
if (QDir(toPath).exists()) {
|
||||||
if (!QDir(toPath).isEmpty()) {
|
if (!QDir(toPath).isEmpty()) {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorFolder);
|
emit localWorkshopCreationStatusChanged(State::ErrorFolder);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
//if(!QDir(toPath + ))
|
//if(!QDir(toPath + ))
|
||||||
@ -68,30 +75,30 @@ void Create::importVideo(QString title, QUrl videoPath, QUrl previewPath, int vi
|
|||||||
} else {
|
} else {
|
||||||
//TODO: Display Error
|
//TODO: Display Error
|
||||||
if (!QDir().mkdir(toPath)) {
|
if (!QDir().mkdir(toPath)) {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorFolderCreation);
|
emit localWorkshopCreationStatusChanged(State::ErrorFolderCreation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copy Video File
|
//Copy Video File
|
||||||
if (QFile::copy(fromVideoPath, toPathWithVideoFile)) {
|
if (QFile::copy(fromVideoPath, toPathWithVideoFile)) {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::CopyVideoFinished);
|
emit localWorkshopCreationStatusChanged(State::CopyVideoFinished);
|
||||||
} else {
|
} else {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorCopyVideo);
|
emit localWorkshopCreationStatusChanged(State::ErrorCopyVideo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copy Image File
|
//Copy Image File
|
||||||
if (QFile::copy(fromImagePath, toPathWithImageFile)) {
|
if (QFile::copy(fromImagePath, toPathWithImageFile)) {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::CopyImageFinished);
|
emit localWorkshopCreationStatusChanged(State::CopyImageFinished);
|
||||||
} else {
|
} else {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorCopyImage);
|
emit localWorkshopCreationStatusChanged(State::ErrorCopyImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copy Project File
|
//Copy Project File
|
||||||
QFile configFile(toPath + "/" + "project.json");
|
QFile configFile(toPath + "/" + "project.json");
|
||||||
|
|
||||||
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::ErrorCopyConfig);
|
emit localWorkshopCreationStatusChanged(State::ErrorCopyConfig);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +115,7 @@ void Create::importVideo(QString title, QUrl videoPath, QUrl previewPath, int vi
|
|||||||
out << configJsonDocument.toJson();
|
out << configJsonDocument.toJson();
|
||||||
configFile.close();
|
configFile.close();
|
||||||
|
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value::Finished);
|
emit localWorkshopCreationStatusChanged(State::Finished);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,22 +203,20 @@ void Create::importVideo(QString title, QUrl videoPath, int timeStamp, int video
|
|||||||
#ifdef QT_NO_DEBUG
|
#ifdef QT_NO_DEBUG
|
||||||
pro.data()->setProgram("ffmpeg.exe");
|
pro.data()->setProgram("ffmpeg.exe");
|
||||||
#endif
|
#endif
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewImage);
|
emit localWorkshopCreationStatusChanged(State::ConvertingPreviewImage);
|
||||||
pro.data()->start();
|
pro.data()->start();
|
||||||
pro.data()->waitForFinished(-1);
|
pro.data()->waitForFinished(-1);
|
||||||
qDebug() << "Done converting video to thumbnail" << pro.data()->readAllStandardOutput();
|
qDebug() << "Done converting video to thumbnail" << pro.data()->readAllStandardOutput();
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewImageFinished);
|
emit localWorkshopCreationStatusChanged(State::ConvertingPreviewImageFinished);
|
||||||
pro.data()->close();
|
pro.data()->close();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
createVideoPreview(tmpPath,((videoDurationInSeconds * videoFrameRate) / 120));
|
//createVideoPreview(tmpPath, ((videoDurationInSeconds * videoFrameRate) / 120));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create::createVideoPreview(QString path, int framesToSkip)
|
void Create::createVideoPreview(QString path, int frames, int length)
|
||||||
{
|
{
|
||||||
|
qDebug() << frames * length;
|
||||||
QtConcurrent::run([=]() {
|
QtConcurrent::run([=]() {
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args.append("-y");
|
args.append("-y");
|
||||||
@ -220,26 +225,97 @@ void Create::createVideoPreview(QString path, int framesToSkip)
|
|||||||
args.append("-speed");
|
args.append("-speed");
|
||||||
args.append("ultrafast");
|
args.append("ultrafast");
|
||||||
args.append("-vf");
|
args.append("-vf");
|
||||||
// We allways want to have a 5 second clip via 24fps -> 120
|
// We allways want to have a 5 second clip via 24fps -> 120 frames
|
||||||
// Divided by the number of frames we can skip (timeInSeconds * Framrate)
|
// Divided by the number of frames we can skip (timeInSeconds * Framrate)
|
||||||
args.append("select='not(mod(n\\," + QString::number(framesToSkip) + "))',setpts=N/FRAME_RATE/TB,scale=480:-1");
|
args.append("select='not(mod(n\\," + QString::number(((frames * length) / 120)) + "))',setpts=N/FRAME_RATE/TB,scale=480:");
|
||||||
|
// Disable audio
|
||||||
args.append("-an");
|
args.append("-an");
|
||||||
args.append("preview.mp4");
|
args.append("preview.mp4");
|
||||||
QScopedPointer<QProcess> pro(new QProcess());
|
QScopedPointer<QProcess> pro(new QProcess());
|
||||||
|
|
||||||
pro.data()->setArguments(args);
|
pro.data()->setArguments(args);
|
||||||
qDebug() << "Start converting video to preview";
|
qDebug() << "Start converting video to preview";
|
||||||
#ifdef QT_DEBUG
|
#ifdef Q_OS_WIN
|
||||||
pro.data()->setProgram("C:/msys64/mingw64/bin/ffmpeg.exe");
|
pro.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe");
|
||||||
#else
|
|
||||||
pro.data()->setProgram("ffmpeg.exe");
|
|
||||||
#endif
|
#endif
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewVideo);
|
|
||||||
pro.data()->start();
|
pro.data()->start();
|
||||||
pro.data()->waitForFinished(-1);
|
pro.data()->waitForFinished(-1);
|
||||||
qDebug() << "Done converting video to preview" << pro.data()->readAllStandardOutput();
|
qDebug() << pro.data()->program() << pro.data()->arguments();
|
||||||
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewVideoFinished);
|
qDebug() << "Done converting video to preview" << pro.data()->readAll() << "\n"
|
||||||
|
<< pro.data()->readAllStandardError();
|
||||||
pro.data()->close();
|
pro.data()->close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Create::createWallpaper(QString videoPath)
|
||||||
|
{
|
||||||
|
videoPath.remove("file:///");
|
||||||
|
|
||||||
|
QtConcurrent::run([=]() {
|
||||||
|
// Get video info
|
||||||
|
QStringList args;
|
||||||
|
args.append("-print_format");
|
||||||
|
args.append("json");
|
||||||
|
args.append("-show_format");
|
||||||
|
args.append("-show_streams");
|
||||||
|
args.append(videoPath);
|
||||||
|
QScopedPointer<QProcess> pro(new QProcess());
|
||||||
|
pro.data()->setArguments(args);
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
pro.data()->setProgram(QApplication::applicationDirPath() + "/ffprobe.exe");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pro.data()->start();
|
||||||
|
pro.data()->waitForFinished(-1);
|
||||||
|
QJsonObject obj;
|
||||||
|
QJsonParseError err;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(pro.data()->readAll(), &err);
|
||||||
|
if (err.error == QJsonParseError::NoError) {
|
||||||
|
obj = doc.object();
|
||||||
|
}
|
||||||
|
|
||||||
|
pro.data()->close();
|
||||||
|
|
||||||
|
// Get video length
|
||||||
|
QJsonObject objFormat = obj.value("format").toObject();
|
||||||
|
bool okParseDuration = false;
|
||||||
|
auto tmpLength = objFormat.value("duration").toVariant().toFloat(&okParseDuration);
|
||||||
|
|
||||||
|
if (!okParseDuration) {
|
||||||
|
qDebug() << "Error parsing video length";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = 0;
|
||||||
|
length = static_cast<int>(tmpLength);
|
||||||
|
|
||||||
|
// Get framerate
|
||||||
|
QJsonArray arrSteams = obj.value("streams").toArray();
|
||||||
|
if (arrSteams.size() < 1) {
|
||||||
|
qDebug() << "Error container does not have any video streams";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject tmpObjStreams = arrSteams.at(0).toObject();
|
||||||
|
|
||||||
|
// The paramter gets us the exact framerate
|
||||||
|
// "avg_frame_rate":"47850000/797509"
|
||||||
|
// so we need no calc the value by dividing the two numbers
|
||||||
|
QString avgFrameRate = tmpObjStreams.value("avg_frame_rate").toVariant().toString();
|
||||||
|
|
||||||
|
QStringList avgFrameRateList = avgFrameRate.split('/', QString::SkipEmptyParts);
|
||||||
|
if (avgFrameRateList.length() != 2) {
|
||||||
|
qDebug() << "Error could not parse streams with length: " << avgFrameRateList.length();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int framerate = 0;
|
||||||
|
float value1 = static_cast<float>(avgFrameRateList.at(0).toInt());
|
||||||
|
float value2 = static_cast<float>(avgFrameRateList.at(1).toInt());
|
||||||
|
|
||||||
|
framerate = qCeil(value1 / value2);
|
||||||
|
|
||||||
|
this->createVideoPreview(videoPath, length, framerate);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,61 +1,86 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QString>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QObject>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QUrl>
|
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
#include "qmlutilities.h"
|
#include "qmlutilities.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
namespace LocalWorkshopCreationStatus {
|
class Create : public QObject {
|
||||||
Q_NAMESPACE
|
|
||||||
enum Value {
|
|
||||||
Idle,
|
|
||||||
Started,
|
|
||||||
CopyVideoFinished,
|
|
||||||
CopyImageFinished,
|
|
||||||
CopyConfigFinished,
|
|
||||||
ConvertingPreviewImage,
|
|
||||||
ConvertingPreviewImageFinished,
|
|
||||||
ConvertingPreviewVideo,
|
|
||||||
ConvertingPreviewVideoFinished,
|
|
||||||
Finished,
|
|
||||||
ErrorFolder,
|
|
||||||
ErrorFolderCreation,
|
|
||||||
ErrorDiskSpace,
|
|
||||||
ErrorCopyVideo,
|
|
||||||
ErrorCopyImage,
|
|
||||||
ErrorCopyConfig,
|
|
||||||
ErrorUnknown,
|
|
||||||
};
|
|
||||||
Q_ENUM_NS(Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
class Create : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Create(Settings* st, QMLUtilities* util,QObject *parent = nullptr);
|
explicit Create(Settings* st, QMLUtilities* util,QObject *parent = nullptr);
|
||||||
|
Create();
|
||||||
|
~Create();
|
||||||
|
|
||||||
|
Q_PROPERTY(State importState READ importState WRITE setImportState NOTIFY importStateChanged)
|
||||||
|
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
Idle,
|
||||||
|
Started,
|
||||||
|
CopyVideoFinished,
|
||||||
|
CopyImageFinished,
|
||||||
|
CopyConfigFinished,
|
||||||
|
ConvertingPreviewImage,
|
||||||
|
ConvertingPreviewImageFinished,
|
||||||
|
ConvertingPreviewVideo,
|
||||||
|
ConvertingPreviewVideoFinished,
|
||||||
|
Finished,
|
||||||
|
ErrorFolder,
|
||||||
|
ErrorFolderCreation,
|
||||||
|
ErrorDiskSpace,
|
||||||
|
ErrorCopyVideo,
|
||||||
|
ErrorCopyImage,
|
||||||
|
ErrorCopyConfig,
|
||||||
|
ErrorUnknown,
|
||||||
|
};
|
||||||
|
Q_ENUM(State)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
State importState() const
|
||||||
|
{
|
||||||
|
return m_importState;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::Value status);
|
void localWorkshopCreationStatusChanged(State status);
|
||||||
|
void importStateChanged(State importState);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void copyProject(QString relativeProjectPath, QString toPath);
|
void copyProject(QString relativeProjectPath, QString toPath);
|
||||||
bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath);
|
bool copyRecursively(const QString& srcFilePath, const QString& tgtFilePath);
|
||||||
|
|
||||||
void importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration);
|
void importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration);
|
||||||
void importVideo(QString title, QUrl videoPath, int timeStamp, int videoDuration, int videoFrameRate);
|
void importVideo(QString title, QUrl videoPath, int timeStamp, int videoDuration, int videoFrameRate);
|
||||||
void createVideoPreview(QString path, int framesToSkip);
|
void createVideoPreview(QString path, int frames, int length);
|
||||||
|
void createWallpaper(QString videoPath);
|
||||||
|
void setImportState(State importState)
|
||||||
|
{
|
||||||
|
if (m_importState == importState)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_importState = importState;
|
||||||
|
emit importStateChanged(m_importState);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings* m_settings;
|
Settings* m_settings;
|
||||||
QMLUtilities* m_utils;
|
QMLUtilities* m_utils;
|
||||||
|
|
||||||
|
State m_importState = State::Idle;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user