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.Controls 2.3
|
||||
import QtQuick.Controls.Material 2.3
|
||||
import net.aimber.create 1.0
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
Connections {
|
||||
target: screenPlayCreate
|
||||
onCreateWallpaperStateChanged: {
|
||||
print(state)
|
||||
if (state === Create.State.ConvertingVideoFinished) {
|
||||
root.state = "finished"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: rectangle1
|
||||
color: "#eeeeee"
|
||||
width: parent.width * .5
|
||||
radius: 3
|
||||
id: wrapperProgressbar
|
||||
height: parent.height * .5
|
||||
z:1
|
||||
anchors {
|
||||
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
|
||||
left: parent.left
|
||||
}
|
||||
@ -18,6 +68,7 @@ Item {
|
||||
Flickable {
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
clip: true
|
||||
contentHeight: txtFFMPEG.paintedHeight
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
snapMode: ScrollBar.SnapOnRelease
|
||||
@ -33,26 +84,79 @@ Item {
|
||||
}
|
||||
wrapMode: Text.WordWrap
|
||||
color: "#626262"
|
||||
text: "asasas"
|
||||
renderType: Text.NativeRendering
|
||||
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 {
|
||||
target: screenPlayCreate
|
||||
onProcessOutput: {
|
||||
txtFFMPEG.text = text
|
||||
txtFFMPEG.text += text
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: rectangle
|
||||
width: parent.width * .5
|
||||
anchors {
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
right: parent.right
|
||||
states: [
|
||||
State {
|
||||
name: "finished"
|
||||
PropertyChanges {
|
||||
target: wrapperProgressbar
|
||||
opacity:0
|
||||
}
|
||||
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);
|
||||
|
||||
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);
|
||||
if (proConvertPreviewMP4.data()->exitStatus() == QProcess::NormalExit) {
|
||||
qDebug() << "normal exit";
|
||||
@ -211,9 +203,6 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
||||
}
|
||||
QString tmpErr = proConvertPreviewMP4.data()->readAllStandardError();
|
||||
if (!tmpErr.isEmpty()) {
|
||||
qDebug() << tmpErr;
|
||||
qDebug() << proConvertPreviewMP4.data()->readAllStandardOutput();
|
||||
qDebug() << proConvertPreviewMP4.data()->readAll();
|
||||
QFile previewVideo(createWallpaperData.exportPath + "/preview.mp4");
|
||||
if (!previewVideo.exists() && !(previewVideo.size() > 0)) {
|
||||
emit processOutput(tmpErr);
|
||||
@ -221,12 +210,10 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
||||
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());
|
||||
proConvertPreviewMP4.data()->close();
|
||||
processOutputTimer.data()->stop();
|
||||
|
||||
emit createWallpaperStateChanged(Create::State::ConvertingPreviewVideoFinished);
|
||||
|
||||
/*
|
||||
@ -253,7 +240,8 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
||||
#endif
|
||||
proConvertGif.data()->start();
|
||||
proConvertGif.data()->waitForFinished(-1);
|
||||
if (!proConvertGif.data()->readAllStandardError().isEmpty()) {
|
||||
QString tmpErrGif = proConvertGif.data()->readAllStandardError();
|
||||
if (!tmpErrGif.isEmpty()) {
|
||||
QFile previewGif(createWallpaperData.exportPath + "/preview.gif");
|
||||
if (!previewGif.exists() && !(previewGif.size() > 0)) {
|
||||
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());
|
||||
proConvertGif.data()->close();
|
||||
emit createWallpaperStateChanged(Create::State::ConvertingPreviewGifFinished);
|
||||
@ -273,6 +258,74 @@ bool Create::createWallpaperVideoPreview(CreateWallpaperData& createWallpaperDat
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
explicit Create(Settings* st, QMLUtilities* util, QObject* parent = nullptr);
|
||||
|
||||
Q_PROPERTY(QString workingDir READ workingDir WRITE setWorkingDir NOTIFY workingDirChanged)
|
||||
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged)
|
||||
|
||||
Create() {}
|
||||
~Create() {}
|
||||
@ -55,6 +56,9 @@ public:
|
||||
ConvertingPreviewGif,
|
||||
ConvertingPreviewGifFinished,
|
||||
ConvertingPreviewGifError,
|
||||
ConvertingVideo,
|
||||
ConvertingVideoFinished,
|
||||
ConvertingVideoError,
|
||||
Finished,
|
||||
ErrorUnknown,
|
||||
};
|
||||
@ -66,11 +70,18 @@ public:
|
||||
return m_workingDir;
|
||||
}
|
||||
|
||||
float progress() const
|
||||
{
|
||||
return m_progress;
|
||||
}
|
||||
|
||||
signals:
|
||||
void createWallpaperStateChanged(Create::State state);
|
||||
void processOutput(QString text);
|
||||
void workingDirChanged(QString workingDir);
|
||||
|
||||
void progressChanged(float progress);
|
||||
|
||||
public slots:
|
||||
void copyProject(QString relativeProjectPath, QString toPath);
|
||||
bool copyRecursively(const QString& srcFilePath, const QString& tgtFilePath);
|
||||
@ -92,9 +103,20 @@ public slots:
|
||||
emit workingDirChanged(m_workingDir);
|
||||
}
|
||||
|
||||
void setProgress(float progress)
|
||||
{
|
||||
if (qFuzzyCompare(m_progress, progress))
|
||||
return;
|
||||
|
||||
qDebug() << progress;
|
||||
m_progress = progress;
|
||||
emit progressChanged(m_progress);
|
||||
}
|
||||
|
||||
private:
|
||||
Settings* m_settings;
|
||||
QMLUtilities* m_utils;
|
||||
|
||||
QString m_workingDir;
|
||||
float m_progress = 0.0f;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user