CuteLogger
Fast and simple logging solution for Qt based applications
findanalysisfilterparser.h
1 /*
2  * Copyright (c) 2025 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef FIND_ANALYSIS_FILTER_PARSER_H
19 #define FIND_ANALYSIS_FILTER_PARSER_H
20 
21 #include "qmltypes/qmlapplication.h"
22 
23 #include <Mlt.h>
24 #include <QFile>
25 #include <QList>
26 #include <QString>
27 
28 class FindAnalysisFilterParser : public Mlt::Parser
29 {
30 private:
31  QList<Mlt::Filter> m_filters;
32  bool m_skipAnalyzed;
33 
34 public:
35  FindAnalysisFilterParser()
36  : Mlt::Parser()
37  , m_skipAnalyzed(true)
38  {}
39 
40  QList<Mlt::Filter> &filters() { return m_filters; }
41 
42  void skipAnalyzed(bool skip) { m_skipAnalyzed = skip; }
43 
44  int on_start_filter(Mlt::Filter *filter)
45  {
46  QString serviceName = filter->get("mlt_service");
47  if (serviceName == "loudness" || serviceName == "vidstab") {
48  // If the results property does not exist, empty, or file does not exist.
49  QString results = filter->get("results");
50  if (results.isEmpty() || !m_skipAnalyzed) {
51  if (serviceName == "vidstab") {
52  // vidstab requires a filename, which is only available when using a project folder.
53  QString filename = filter->get("filename");
54  if (filename.isEmpty() || filename.endsWith("vidstab.trf")) {
55  filename = QmlApplication::getNextProjectFile("stab");
56  }
57  if (!filename.isEmpty()) {
58  filter->set("filename", filename.toUtf8().constData());
59  m_filters << Mlt::Filter(*filter);
60 
61  // Touch file to prevent overwriting the same file
62  QFile file(filename);
63  file.open(QIODevice::WriteOnly);
64  file.resize(0);
65  file.close();
66  }
67  } else {
68  m_filters << Mlt::Filter(*filter);
69  }
70  }
71  }
72  return 0;
73  }
74  int on_start_producer(Mlt::Producer *) { return 0; }
75  int on_end_producer(Mlt::Producer *) { return 0; }
76  int on_start_playlist(Mlt::Playlist *) { return 0; }
77  int on_end_playlist(Mlt::Playlist *) { return 0; }
78  int on_start_tractor(Mlt::Tractor *) { return 0; }
79  int on_end_tractor(Mlt::Tractor *) { return 0; }
80  int on_start_multitrack(Mlt::Multitrack *) { return 0; }
81  int on_end_multitrack(Mlt::Multitrack *) { return 0; }
82  int on_start_track() { return 0; }
83  int on_end_track() { return 0; }
84  int on_end_filter(Mlt::Filter *) { return 0; }
85  int on_start_transition(Mlt::Transition *) { return 0; }
86  int on_end_transition(Mlt::Transition *) { return 0; }
87  int on_start_chain(Mlt::Chain *) { return 0; }
88  int on_end_chain(Mlt::Chain *) { return 0; }
89  int on_start_link(Mlt::Link *) { return 0; }
90  int on_end_link(Mlt::Link *) { return 0; }
91 };
92 
93 #endif // FIND_ANALYSIS_FILTER_PARSER_H