1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-26 12:42:34 +01:00

Fix displaying of error messages

Fix abort not being called
This commit is contained in:
Elias Steurer 2019-10-12 11:42:56 +02:00
parent 08414a3d01
commit 17f6f8110b
6 changed files with 69 additions and 32 deletions

View File

@ -59,15 +59,9 @@ Item {
}
wrapMode: Text.WordWrap
color: "#626262"
text: ScreenPlay.create.ffmpegOutput
height: txtFFMPEGDebug.paintedHeight
}
Connections {
target: ScreenPlay.create
onProcessOutput: {
txtFFMPEGDebug.text = text
}
}
}
}

View File

@ -174,8 +174,8 @@ Item {
}
PropertyChanges {
target: loader_wrapperContent
opacity: 0
z: 0
opacity: 1
z: 1
source: "qrc:/qml/Create/Wizards/CreateWallpaper/CreateWallpaperResult.qml"
}
},

View File

@ -32,6 +32,7 @@ Create::Create()
void Create::createWallpaperStart(QString videoPath)
{
clearFfmpegOutput();
videoPath.remove("file:///");
QDir dir;
@ -49,11 +50,14 @@ void Create::createWallpaperStart(QString videoPath)
m_createImportVideoThread = new QThread();
m_createImportVideo = new CreateImportVideo(videoPath, workingDir());
connect(m_createImportVideo, &CreateImportVideo::processOutput, this, [this](QString text) {
appendFfmpegOutput(text);
});
connect(m_createImportVideo, &CreateImportVideo::createWallpaperStateChanged, this, &Create::createWallpaperStateChanged);
connect(m_createImportVideo, &CreateImportVideo::progressChanged, this, &Create::setProgress);
connect(m_createImportVideoThread, &QThread::started, m_createImportVideo, &CreateImportVideo::process);
connect(m_createImportVideo, &CreateImportVideo::canceled, this, &Create::abortAndCleanup);
connect(m_createImportVideo, &CreateImportVideo::abortAndCleanup, this, &Create::abortAndCleanup);
connect(m_createImportVideo, &CreateImportVideo::finished, m_createImportVideoThread, &QThread::quit);
connect(m_createImportVideo, &CreateImportVideo::finished, m_createImportVideo, &QObject::deleteLater);
@ -61,6 +65,7 @@ void Create::createWallpaperStart(QString videoPath)
m_createImportVideo->moveToThread(m_createImportVideoThread);
m_createImportVideoThread->start();
}
void Create::saveWallpaper(QString title, QString description, QString filePath, QString previewImagePath, QString youtube, QVector<QString> tags)
@ -146,6 +151,7 @@ void Create::saveWallpaper(QString title, QString description, QString filePath,
void Create::abortAndCleanup()
{
qWarning() << "Abort and Cleanup!";
if (m_createImportVideo == nullptr || m_createImportVideoThread == nullptr) {
qDebug() << m_createImportVideo << m_createImportVideoThread;

View File

@ -36,6 +36,7 @@ class Create : public QObject {
Q_PROPERTY(QString workingDir READ workingDir WRITE setWorkingDir NOTIFY workingDirChanged)
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged)
Q_PROPERTY(QString ffmpegOutput READ ffmpegOutput WRITE appendFfmpegOutput NOTIFY ffmpegOutputChanged)
public:
explicit Create(
@ -54,12 +55,17 @@ public:
return m_workingDir;
}
QString ffmpegOutput() const
{
return m_ffmpegOutput;
}
signals:
void createWallpaperStateChanged(CreateImportVideo::ImportVideoState state);
void processOutput(QString text);
void progressChanged(float progress);
void abortCreateWallpaper();
void workingDirChanged(QString workingDir);
void ffmpegOutputChanged(QString ffmpegOutput);
public slots:
void createWallpaperStart(QString videoPath);
@ -84,6 +90,17 @@ public slots:
emit workingDirChanged(m_workingDir);
}
void appendFfmpegOutput(QString ffmpegOutput)
{
m_ffmpegOutput += ffmpegOutput;
emit ffmpegOutputChanged(m_ffmpegOutput);
}
void clearFfmpegOutput(){
m_ffmpegOutput = "";
emit ffmpegOutputChanged(m_ffmpegOutput);
}
private:
CreateImportVideo* m_createImportVideo {nullptr};
QThread* m_createImportVideoThread {nullptr};
@ -92,5 +109,6 @@ private:
float m_progress { 0.0F };
QString m_workingDir;
QString m_ffmpegOutput;
};
}

View File

@ -29,25 +29,37 @@ CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& ex
void CreateImportVideo::process()
{
if (!createWallpaperInfo() || QThread::currentThread()->isInterruptionRequested())
if (!createWallpaperInfo() || QThread::currentThread()->isInterruptionRequested()) {
emit abortAndCleanup();
return;
}
if (!createWallpaperImagePreview() || QThread::currentThread()->isInterruptionRequested())
if (!createWallpaperImagePreview() || QThread::currentThread()->isInterruptionRequested()) {
emit abortAndCleanup();
return;
}
if (!createWallpaperVideoPreview() || QThread::currentThread()->isInterruptionRequested())
if (!createWallpaperVideoPreview() || QThread::currentThread()->isInterruptionRequested()) {
emit abortAndCleanup();
return;
}
if (!createWallpaperGifPreview() || QThread::currentThread()->isInterruptionRequested())
if (!createWallpaperGifPreview() || QThread::currentThread()->isInterruptionRequested()) {
emit abortAndCleanup();
return;
}
if (!createWallpaperVideo() || QThread::currentThread()->isInterruptionRequested())
if (!createWallpaperVideo() || QThread::currentThread()->isInterruptionRequested()) {
emit abortAndCleanup();
return;
}
// If the video has no audio we can skip the extraction
if (!m_skipAudio) {
if (!extractWallpaperAudio() || QThread::currentThread()->isInterruptionRequested())
if (!extractWallpaperAudio() || QThread::currentThread()->isInterruptionRequested()) {
emit abortAndCleanup();
return;
}
}
emit createWallpaperStateChanged(ImportVideoState::Finished);
@ -90,6 +102,7 @@ bool CreateImportVideo::createWallpaperInfo()
QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson(pro->readAll(), &err);
if (err.error != QJsonParseError::NoError) {
qDebug() << "Error parsing ffmpeg json output";
emit processOutput("Error parsing ffmpeg json output");
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError);
return false;
@ -98,6 +111,8 @@ bool CreateImportVideo::createWallpaperInfo()
obj = doc.object();
if (obj.empty()) {
qDebug() << "Error! File could not be parsed.";
emit processOutput("Error! File could not be parsed.");
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError);
pro->close();
return false;
@ -125,6 +140,8 @@ bool CreateImportVideo::createWallpaperInfo()
// Display error if wallpaper has no video
if (!hasVideoStream) {
qDebug() << "Error! File has no video Stream!";
emit processOutput("Error! File has no video Stream!");
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoHasNoVideoStreamError);
return false;
}
@ -137,8 +154,10 @@ bool CreateImportVideo::createWallpaperInfo()
m_numberOfFrames = videoStream.value("nb_frames").toString().toInt(&okParseNumberOfFrames);
if (!okParseNumberOfFrames) {
qDebug() << "Error parsing number of frames";
emit processOutput("Error parsing number of frames");
qDebug() << "Error parsing number of frames. Is this really a valid video File?";
emit processOutput("Error parsing number of frames. Is this really a valid video File?");
QJsonDocument tmpVideoStreamDoc(videoStream);
emit processOutput(tmpVideoStreamDoc.toJson());
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError);
return false;
}
@ -150,8 +169,8 @@ bool CreateImportVideo::createWallpaperInfo()
float tmpLength = objFormat.value("duration").toVariant().toFloat(&okParseDuration);
if (!okParseDuration) {
qDebug() << "Error parsing video length";
emit processOutput("Error parsing video length");
qDebug() << "Error parsing video length. Is this really a valid video File?";
emit processOutput("Error parsing video length. Is this really a valid video File?");
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError);
return false;
}
@ -163,6 +182,7 @@ bool CreateImportVideo::createWallpaperInfo()
QJsonArray arrSteams = obj.value("streams").toArray();
if (arrSteams.empty()) {
qDebug() << "Error container does not have any video streams";
emit processOutput("Error container does not have any video streams");
return false;
}
@ -176,6 +196,7 @@ bool CreateImportVideo::createWallpaperInfo()
QStringList avgFrameRateList = avgFrameRate.split('/', QString::SkipEmptyParts);
if (avgFrameRateList.length() != 2) {
qDebug() << "Error could not parse streams with length: " << avgFrameRateList.length();
emit processOutput("Error could not parse streams with length: " + QString::number(avgFrameRateList.length()));
return false;
}
@ -230,8 +251,8 @@ bool CreateImportVideo::createWallpaperVideoPreview()
if (!ok)
return;
qDebug() << currentFrame << static_cast<float>((m_framerate * 5 ));
float progress = currentFrame / static_cast<float>((m_framerate * 5 ));
qDebug() << currentFrame << static_cast<float>((m_framerate * 5));
float progress = currentFrame / static_cast<float>((m_framerate * 5));
this->setProgress(progress);
}
@ -258,7 +279,7 @@ bool CreateImportVideo::createWallpaperVideoPreview()
return false;
}
//this->processOutput(proConvertPreviewWebM->readAll());
this->processOutput(proConvertPreviewWebM->readAll());
proConvertPreviewWebM->close();
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewVideoFinished);
@ -312,7 +333,7 @@ bool CreateImportVideo::createWallpaperGifPreview()
}
}
//this->processOutput(proConvertGif->readAll());
this->processOutput(proConvertGif->readAll());
proConvertGif->close();
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewGifFinished);
@ -370,7 +391,7 @@ bool CreateImportVideo::createWallpaperImagePreview()
}
}
//this->processOutput(proConvertImage->readAll());
this->processOutput(proConvertImage->readAll());
proConvertImage->close();
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImageFinished);
@ -416,13 +437,13 @@ bool CreateImportVideo::createWallpaperVideo()
proConvertVideo->setProgram(QApplication::applicationDirPath() + "/ffmpeg");
#endif
proConvertVideo->setProcessChannelMode(QProcess::MergedChannels);
connect(proConvertVideo.data(), &QProcess::errorOccurred, this, [&](QProcess::ProcessError error){
connect(proConvertVideo.data(), &QProcess::errorOccurred, this, [&](QProcess::ProcessError error) {
qDebug() << error;
});
connect(proConvertVideo.data(), &QProcess::readyReadStandardOutput, this, [&]() {
QString tmpOut = proConvertVideo->readAllStandardOutput();
if(tmpOut.contains("Conversion failed!")){
if (tmpOut.contains("Conversion failed!")) {
emit createWallpaperStateChanged(ImportVideoState::ConvertingVideoError);
}
auto tmpList = tmpOut.split(QRegExp("\\s+"), QString::SkipEmptyParts);
@ -436,7 +457,6 @@ bool CreateImportVideo::createWallpaperVideo()
float progress = currentFrame / m_numberOfFrames;
this->setProgress(progress);
}
this->processOutput(tmpOut);
@ -522,7 +542,7 @@ bool CreateImportVideo::extractWallpaperAudio()
}
}
//this->processOutput(proConvertAudio->readAll());
this->processOutput(proConvertAudio->readAll());
proConvertAudio->close();
emit createWallpaperStateChanged(ImportVideoState::ConvertingAudioFinished);

View File

@ -86,8 +86,7 @@ signals:
void createWallpaperStateChanged(CreateImportVideo::ImportVideoState state);
void processOutput(QString text);
void finished();
void canceled();
void abortAndCleanup();
void progressChanged(float progress);
public slots: