mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-07 03:22:33 +01:00
Add working video conversion
This commit is contained in:
parent
c16edb7a84
commit
69385d76a1
@ -1,16 +1,66 @@
|
|||||||
import QtQuick 2.9
|
import QtQuick 2.9
|
||||||
import QtQuick.Controls 2.3
|
import QtQuick.Controls 2.3
|
||||||
|
import QtQuick.Controls.Material 2.3
|
||||||
|
import net.aimber.create 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: screenPlayCreate
|
||||||
|
onCreateWallpaperStateChanged: {
|
||||||
|
print(state)
|
||||||
|
if (state === Create.State.ConvertingVideoFinished) {
|
||||||
|
root.state = "finished"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: rectangle1
|
id: wrapperProgressbar
|
||||||
color: "#eeeeee"
|
height: parent.height * .5
|
||||||
width: parent.width * .5
|
z:1
|
||||||
radius: 3
|
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
|
right: parent.right
|
||||||
|
left: parent.left
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: txtProgress
|
||||||
|
text: Math.floor(screenPlayCreate.progress) + "%"
|
||||||
|
font.pixelSize: 42
|
||||||
|
color: "#626262"
|
||||||
|
renderType: Text.NativeRendering
|
||||||
|
anchors {
|
||||||
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
bottom: progressBar.top
|
||||||
|
bottomMargin: 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressBar {
|
||||||
|
id: progressBar
|
||||||
|
value: screenPlayCreate.progress
|
||||||
|
from: 0
|
||||||
|
to: 100
|
||||||
|
anchors {
|
||||||
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
bottom: parent.bottom
|
||||||
|
bottomMargin: 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: wrapperFFMPEGOutput
|
||||||
|
color: "#eeeeee"
|
||||||
|
radius: 3
|
||||||
|
z:1
|
||||||
|
anchors {
|
||||||
|
top: wrapperProgressbar.bottom
|
||||||
|
topMargin: 30
|
||||||
|
right: parent.right
|
||||||
bottom: parent.bottom
|
bottom: parent.bottom
|
||||||
left: parent.left
|
left: parent.left
|
||||||
}
|
}
|
||||||
@ -18,6 +68,7 @@ Item {
|
|||||||
Flickable {
|
Flickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
focus: true
|
focus: true
|
||||||
|
clip: true
|
||||||
contentHeight: txtFFMPEG.paintedHeight
|
contentHeight: txtFFMPEG.paintedHeight
|
||||||
ScrollBar.vertical: ScrollBar {
|
ScrollBar.vertical: ScrollBar {
|
||||||
snapMode: ScrollBar.SnapOnRelease
|
snapMode: ScrollBar.SnapOnRelease
|
||||||
@ -33,26 +84,79 @@ Item {
|
|||||||
}
|
}
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
color: "#626262"
|
color: "#626262"
|
||||||
|
text: "asasas"
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
height: txtFFMPEG.paintedHeight
|
height: txtFFMPEG.paintedHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: wrapperFinished
|
||||||
|
z:0
|
||||||
|
anchors.fill: parent
|
||||||
|
opacity: 0
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: txtDone
|
||||||
|
text: qsTr("Video creation successful!")
|
||||||
|
font.pixelSize: 42
|
||||||
|
color: Material.color(Material.Green)
|
||||||
|
renderType: Text.NativeRendering
|
||||||
|
anchors {
|
||||||
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
top: parent.top
|
||||||
|
topMargin: 30
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: screenPlayCreate
|
target: screenPlayCreate
|
||||||
onProcessOutput: {
|
onProcessOutput: {
|
||||||
txtFFMPEG.text = text
|
txtFFMPEG.text += text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
states: [
|
||||||
Rectangle {
|
State {
|
||||||
id: rectangle
|
name: "finished"
|
||||||
width: parent.width * .5
|
PropertyChanges {
|
||||||
anchors {
|
target: wrapperProgressbar
|
||||||
top: parent.top
|
opacity:0
|
||||||
bottom: parent.bottom
|
}
|
||||||
right: parent.right
|
PropertyChanges {
|
||||||
|
target: wrapperFFMPEGOutput
|
||||||
|
opacity:0
|
||||||
|
}
|
||||||
|
PropertyChanges {
|
||||||
|
target: wrapperFinished
|
||||||
|
opacity:1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
|
transitions: [
|
||||||
|
Transition {
|
||||||
|
from: "0"
|
||||||
|
to: "finished"
|
||||||
|
PropertyAnimation {
|
||||||
|
target: wrapperFFMPEGOutput
|
||||||
|
duration: 200
|
||||||
|
property: "opacity"
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
}
|
||||||
|
PropertyAnimation {
|
||||||
|
target: wrapperProgressbar
|
||||||
|
duration: 200
|
||||||
|
property: "opacity"
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
}
|
||||||
|
PropertyAnimation {
|
||||||
|
target: wrapperFinished
|
||||||
|
duration: 200
|
||||||
|
property: "opacity"
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -195,14 +195,6 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
|||||||
emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideo);
|
emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideo);
|
||||||
|
|
||||||
proConvertPreviewMP4.data()->start();
|
proConvertPreviewMP4.data()->start();
|
||||||
|
|
||||||
QScopedPointer<QTimer> processOutputTimer(new QTimer());
|
|
||||||
|
|
||||||
// connect(processOutputTimer.data(), &QTimer::timeout, [&]() {
|
|
||||||
// qDebug() << "### " << proConvertPreviewMP4.data()->readAll();
|
|
||||||
// this->processOutput(proConvertPreviewMP4.data()->readAll());
|
|
||||||
// });
|
|
||||||
processOutputTimer.data()->start(100);
|
|
||||||
proConvertPreviewMP4.data()->waitForFinished(-1);
|
proConvertPreviewMP4.data()->waitForFinished(-1);
|
||||||
if (proConvertPreviewMP4.data()->exitStatus() == QProcess::NormalExit) {
|
if (proConvertPreviewMP4.data()->exitStatus() == QProcess::NormalExit) {
|
||||||
qDebug() << "normal exit";
|
qDebug() << "normal exit";
|
||||||
@ -211,9 +203,6 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
|||||||
}
|
}
|
||||||
QString tmpErr = proConvertPreviewMP4.data()->readAllStandardError();
|
QString tmpErr = proConvertPreviewMP4.data()->readAllStandardError();
|
||||||
if (!tmpErr.isEmpty()) {
|
if (!tmpErr.isEmpty()) {
|
||||||
qDebug() << tmpErr;
|
|
||||||
qDebug() << proConvertPreviewMP4.data()->readAllStandardOutput();
|
|
||||||
qDebug() << proConvertPreviewMP4.data()->readAll();
|
|
||||||
QFile previewVideo(createWallpaperData.exportPath + "/preview.mp4");
|
QFile previewVideo(createWallpaperData.exportPath + "/preview.mp4");
|
||||||
if (!previewVideo.exists() && !(previewVideo.size() > 0)) {
|
if (!previewVideo.exists() && !(previewVideo.size() > 0)) {
|
||||||
emit processOutput(tmpErr);
|
emit processOutput(tmpErr);
|
||||||
@ -221,12 +210,10 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// qDebug() << proConvertPreviewMP4.data()->program() << proConvertPreviewMP4.data()->arguments();
|
|
||||||
// qDebug() << "Done converting video to preview" << proConvertPreviewMP4.data()->readAll() << "\n"
|
|
||||||
// << proConvertPreviewMP4.data()->readAllStandardError();
|
|
||||||
this->processOutput(proConvertPreviewMP4.data()->readAll());
|
this->processOutput(proConvertPreviewMP4.data()->readAll());
|
||||||
proConvertPreviewMP4.data()->close();
|
proConvertPreviewMP4.data()->close();
|
||||||
processOutputTimer.data()->stop();
|
|
||||||
emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideoFinished);
|
emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideoFinished);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -253,7 +240,8 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
|||||||
#endif
|
#endif
|
||||||
proConvertGif.data()->start();
|
proConvertGif.data()->start();
|
||||||
proConvertGif.data()->waitForFinished(-1);
|
proConvertGif.data()->waitForFinished(-1);
|
||||||
if (!proConvertGif.data()->readAllStandardError().isEmpty()) {
|
QString tmpErrGif = proConvertGif.data()->readAllStandardError();
|
||||||
|
if (!tmpErrGif.isEmpty()) {
|
||||||
QFile previewGif(createWallpaperData.exportPath + "/preview.gif");
|
QFile previewGif(createWallpaperData.exportPath + "/preview.gif");
|
||||||
if (!previewGif.exists() && !(previewGif.size() > 0)) {
|
if (!previewGif.exists() && !(previewGif.size() > 0)) {
|
||||||
emit createWallpaperStateChanged(Create::State::ConvertingPreviewGifError);
|
emit createWallpaperStateChanged(Create::State::ConvertingPreviewGifError);
|
||||||
@ -261,9 +249,6 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << proConvertGif.data()->program() << proConvertGif.data()->arguments();
|
|
||||||
// qDebug() << "Done converting video to preview" << proConvertGif.data()->readAll() << "\n"
|
|
||||||
// << proConvertGif.data()->readAllStandardError();
|
|
||||||
this->processOutput(proConvertPreviewMP4.data()->readAll());
|
this->processOutput(proConvertPreviewMP4.data()->readAll());
|
||||||
proConvertGif.data()->close();
|
proConvertGif.data()->close();
|
||||||
emit createWallpaperStateChanged(Create::State::ConvertingPreviewGifFinished);
|
emit createWallpaperStateChanged(Create::State::ConvertingPreviewGifFinished);
|
||||||
@ -273,6 +258,74 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
|||||||
|
|
||||||
bool Create::createWallpaperVideo(CreateWallpaperData& createWallpaperData)
|
bool Create::createWallpaperVideo(CreateWallpaperData& createWallpaperData)
|
||||||
{
|
{
|
||||||
|
emit createWallpaperStateChanged(Create::State::ConvertingVideo);
|
||||||
|
|
||||||
|
QStringList args;
|
||||||
|
args.append("-hide_banner");
|
||||||
|
args.append("-y");
|
||||||
|
args.append("-stats");
|
||||||
|
args.append("-i");
|
||||||
|
args.append(createWallpaperData.videoPath);
|
||||||
|
args.append("-c:v");
|
||||||
|
args.append("libvpx-vp9");
|
||||||
|
args.append("-crf");
|
||||||
|
args.append("30");
|
||||||
|
args.append("-threads");
|
||||||
|
args.append("16");
|
||||||
|
args.append("-slices");
|
||||||
|
args.append("16");
|
||||||
|
args.append("-cpu-used");
|
||||||
|
args.append("4");
|
||||||
|
args.append("-pix_fmt");
|
||||||
|
args.append("yuv420p");
|
||||||
|
args.append("-b:v");
|
||||||
|
args.append("0");
|
||||||
|
args.append(createWallpaperData.exportPath + "/video.webm");
|
||||||
|
|
||||||
|
QScopedPointer<QProcess> proConvertVideo(new QProcess());
|
||||||
|
proConvertVideo.data()->setArguments(args);
|
||||||
|
proConvertVideo.data()->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
proConvertVideo.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe");
|
||||||
|
qDebug() << "Start converting video";
|
||||||
|
|
||||||
|
connect(proConvertVideo.data(), &QProcess::readyReadStandardOutput, this, [&]() {
|
||||||
|
QString tmpOut = proConvertVideo.data()->readAllStandardOutput();
|
||||||
|
auto tmpList = tmpOut.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
||||||
|
if (tmpList.length() > 2) {
|
||||||
|
bool ok = false;
|
||||||
|
float currentFrame = QString(tmpList.at(1)).toFloat(&ok);
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float progress = currentFrame / createWallpaperData.length;
|
||||||
|
|
||||||
|
this->setProgress(progress);
|
||||||
|
}
|
||||||
|
this->processOutput(tmpOut);
|
||||||
|
});
|
||||||
|
|
||||||
|
// For some reason we only get output if we use execute instead of start....?!
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
//proConvertVideo.data()->execute(QApplication::applicationDirPath() + "/ffmpeg.exe", args);
|
||||||
|
#endif
|
||||||
|
proConvertVideo.data()->start(QIODevice::ReadOnly);
|
||||||
|
proConvertVideo.data()->waitForFinished(-1);
|
||||||
|
QString out = proConvertVideo.data()->readAllStandardOutput();
|
||||||
|
|
||||||
|
this->processOutput(out);
|
||||||
|
QString tmpErrVideo = proConvertVideo.data()->readAllStandardError();
|
||||||
|
if (!tmpErrVideo.isEmpty()) {
|
||||||
|
QFile video(createWallpaperData.exportPath + "/video.webm");
|
||||||
|
if (!video.exists() && !(video.size() > 0)) {
|
||||||
|
emit createWallpaperStateChanged(Create::State::ConvertingVideoError);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proConvertVideo.data()->close();
|
||||||
|
emit createWallpaperStateChanged(Create::State::ConvertingVideoFinished);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ public:
|
|||||||
explicit Create(Settings* st, QMLUtilities* util, QObject* parent = nullptr);
|
explicit Create(Settings* st, QMLUtilities* util, QObject* parent = nullptr);
|
||||||
|
|
||||||
Q_PROPERTY(QString workingDir READ workingDir WRITE setWorkingDir NOTIFY workingDirChanged)
|
Q_PROPERTY(QString workingDir READ workingDir WRITE setWorkingDir NOTIFY workingDirChanged)
|
||||||
|
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged)
|
||||||
|
|
||||||
Create() {}
|
Create() {}
|
||||||
~Create() {}
|
~Create() {}
|
||||||
@ -55,6 +56,9 @@ public:
|
|||||||
ConvertingPreviewGif,
|
ConvertingPreviewGif,
|
||||||
ConvertingPreviewGifFinished,
|
ConvertingPreviewGifFinished,
|
||||||
ConvertingPreviewGifError,
|
ConvertingPreviewGifError,
|
||||||
|
ConvertingVideo,
|
||||||
|
ConvertingVideoFinished,
|
||||||
|
ConvertingVideoError,
|
||||||
Finished,
|
Finished,
|
||||||
ErrorUnknown,
|
ErrorUnknown,
|
||||||
};
|
};
|
||||||
@ -66,11 +70,18 @@ public:
|
|||||||
return m_workingDir;
|
return m_workingDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float progress() const
|
||||||
|
{
|
||||||
|
return m_progress;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void createWallpaperStateChanged(Create::State state);
|
void createWallpaperStateChanged(Create::State state);
|
||||||
void processOutput(QString text);
|
void processOutput(QString text);
|
||||||
void workingDirChanged(QString workingDir);
|
void workingDirChanged(QString workingDir);
|
||||||
|
|
||||||
|
void progressChanged(float progress);
|
||||||
|
|
||||||
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);
|
||||||
@ -92,9 +103,20 @@ public slots:
|
|||||||
emit workingDirChanged(m_workingDir);
|
emit workingDirChanged(m_workingDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setProgress(float progress)
|
||||||
|
{
|
||||||
|
if (qFuzzyCompare(m_progress, progress))
|
||||||
|
return;
|
||||||
|
|
||||||
|
qDebug() << progress;
|
||||||
|
m_progress = progress;
|
||||||
|
emit progressChanged(m_progress);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings* m_settings;
|
Settings* m_settings;
|
||||||
QMLUtilities* m_utils;
|
QMLUtilities* m_utils;
|
||||||
|
|
||||||
QString m_workingDir;
|
QString m_workingDir;
|
||||||
|
float m_progress = 0.0f;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user