forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideoqualityjob.cpp
More file actions
95 lines (85 loc) · 3.17 KB
/
videoqualityjob.cpp
File metadata and controls
95 lines (85 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright (c) 2012-2017 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "videoqualityjob.h"
#include <QAction>
#include <QFile>
#include <QDomDocument>
#include <QTextStream>
#include <QFileInfo>
#include <QUrl>
#include <QDesktopServices>
#include "mainwindow.h"
#include "dialogs/textviewerdialog.h"
#include "util.h"
VideoQualityJob::VideoQualityJob(const QString &name, const QString &xml,
const QString &reportPath, int frameRateNum, int frameRateDen)
: MeltJob(name, xml, frameRateNum, frameRateDen)
, m_reportPath(reportPath)
{
QAction *action = new QAction(tr("Open"), this);
action->setToolTip(tr("Open original and encoded side-by-side in the Shotcut player"));
connect(action, SIGNAL(triggered()), this, SLOT(onOpenTiggered()));
m_successActions << action;
action = new QAction(tr("View Report"), this);
connect(action, SIGNAL(triggered()), this, SLOT(onViewReportTriggered()));
m_successActions << action;
action = new QAction(tr("Show In Folder"), this);
connect(action, SIGNAL(triggered()), this, SLOT(onShowFolderTriggered()));
m_successActions << action;
setLabel(tr("Measure %1").arg(objectName()));
setStandardOutputFile(reportPath);
}
void VideoQualityJob::onOpenTiggered()
{
// Parse the XML.
QFile file(xmlPath());
file.open(QIODevice::ReadOnly);
QDomDocument dom(xmlPath());
dom.setContent(&file);
file.close();
// Locate the VQM transition.
QDomNodeList transitions = dom.elementsByTagName("transition");
for (int i = 0; i < transitions.length(); i++ ) {
QDomElement property = transitions.at(i).firstChildElement("property");
while (!property.isNull()) {
// Change the render property to 1.
if (property.attribute("name") == "render") {
property.firstChild().setNodeValue("1");
// Save the new XML.
file.open(QIODevice::WriteOnly);
QTextStream textStream(&file);
dom.save(textStream, 2);
file.close();
MAIN.open(xmlPath().toUtf8().constData());
break;
}
property = property.nextSiblingElement("property");
}
}
}
void VideoQualityJob::onViewReportTriggered()
{
TextViewerDialog dialog(&MAIN);
dialog.setWindowTitle(tr("Video Quality Measurement"));
QFile f(m_reportPath);
f.open(QIODevice::ReadOnly);
QString s(f.readAll());
f.close();
dialog.setText(s);
dialog.exec();
}