CuteLogger
Fast and simple logging solution for Qt based applications
encodedock.h
1 /*
2  * Copyright (c) 2012-2024 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 ENCODEDOCK_H
19 #define ENCODEDOCK_H
20 
21 #include "settings.h"
22 
23 #include <MltProperties.h>
24 #include <QDockWidget>
25 #include <QDomElement>
26 #include <QSortFilterProxyModel>
27 #include <QStandardItemModel>
28 #include <QStringList>
29 
30 class QTreeWidgetItem;
31 class QTemporaryFile;
32 namespace Ui {
33 class EncodeDock;
34 }
35 class AbstractJob;
36 class MeltJob;
37 namespace Mlt {
38 class Service;
39 class Producer;
40 class Filter;
41 } // namespace Mlt
42 
43 class PresetsProxyModel : public QSortFilterProxyModel
44 {
45 protected:
46  bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
47 };
48 
49 class EncodeDock : public QDockWidget
50 {
51  Q_OBJECT
52 
53 public:
54  explicit EncodeDock(QWidget *parent = 0);
55  ~EncodeDock();
56 
57  void loadPresetFromProperties(Mlt::Properties &);
58  bool isExportInProgress() const;
59 
60 signals:
61  void captureStateChanged(bool);
62  void createOrEditFilterOnOutput(Mlt::Filter *, const QStringList & = {});
63 
64 public slots:
65  void onAudioChannelsChanged();
66  void onProducerOpened();
67  void onProfileChanged();
68  void onReframeChanged();
69  void on_hwencodeButton_clicked();
70  bool detectHardwareEncoders();
71 
72 private slots:
73  void on_presetsTree_clicked(const QModelIndex &index);
74  void on_presetsTree_activated(const QModelIndex &index);
75 
76  void on_encodeButton_clicked();
77 
78  void on_streamButton_clicked();
79 
80  void on_addPresetButton_clicked();
81 
82  void on_removePresetButton_clicked();
83 
84  void onFinished(AbstractJob *, bool isSuccess);
85 
86  void on_stopCaptureButton_clicked();
87 
88  void on_videoRateControlCombo_activated(int index);
89 
90  void on_audioRateControlCombo_activated(int index);
91 
92  void on_scanModeCombo_currentIndexChanged(int index);
93 
94  void on_presetsSearch_textChanged(const QString &search);
95 
96  void on_resetButton_clicked();
97 
98  void openCaptureFile();
99 
100  void on_formatCombo_currentIndexChanged(int index);
101 
102  void on_videoBufferDurationChanged();
103 
104  void on_gopSpinner_valueChanged(int value);
105 
106  void on_fromCombo_currentIndexChanged(int index);
107 
108  void on_videoCodecCombo_currentIndexChanged(int index);
109 
110  void on_audioCodecCombo_currentIndexChanged(int index);
111 
112  void setAudioChannels(int channels);
113 
114  void on_widthSpinner_editingFinished();
115 
116  void on_heightSpinner_editingFinished();
117 
118  void on_advancedButton_clicked(bool checked);
119 
120  void on_hwencodeCheckBox_clicked(bool checked);
121 
122  void on_advancedCheckBox_clicked(bool checked);
123 
124  void on_fpsSpinner_editingFinished();
125 
126  void on_fpsComboBox_activated(int arg1);
127 
128  void on_videoQualitySpinner_valueChanged(int vq);
129 
130  void on_audioQualitySpinner_valueChanged(int aq);
131 
132  void on_parallelCheckbox_clicked(bool checked);
133 
134  void on_resolutionComboBox_activated(int arg1);
135 
136  void on_reframeButton_clicked();
137 
138  void on_aspectNumSpinner_valueChanged(int value);
139 
140  void on_aspectDenSpinner_valueChanged(int value);
141 
142 private:
143  enum {
144  RateControlAverage = 0,
145  RateControlConstant,
146  RateControlQuality,
147  RateControlConstrained
148  };
149  enum {
150  AudioChannels1 = 0,
151  AudioChannels2,
152  AudioChannels4,
153  AudioChannels6,
154  };
155  Ui::EncodeDock *ui;
156  Mlt::Properties *m_presets;
157  QScopedPointer<MeltJob> m_immediateJob;
158  QString m_extension;
159  Mlt::Properties *m_profiles;
160  PresetsProxyModel m_presetsModel;
161  QStringList m_outputFilenames;
162  bool m_isDefaultSettings;
163  double m_fps;
164  QStringList m_intraOnlyCodecs;
165  QStringList m_losslessVideoCodecs;
166  QStringList m_losslessAudioCodecs;
167 
168  void loadPresets();
169  Mlt::Properties *collectProperties(int realtime, bool includeProfile = false);
170  void collectProperties(QDomElement &node, int realtime);
171  void setSubtitleProperties(QDomElement &node, Mlt::Producer *service);
172  QPoint addConsumerElement(
173  Mlt::Producer *service, QDomDocument &dom, const QString &target, int realtime, int pass);
174  MeltJob *convertReframe(Mlt::Producer *service,
175  QTemporaryFile *tmp,
176  const QString &target,
177  int realtime,
178  int pass,
179  const QThread::Priority priority);
180  MeltJob *createMeltJob(Mlt::Producer *service,
181  const QString &target,
182  int realtime,
183  int pass = 0,
184  const QThread::Priority priority = Settings.jobPriority());
185  void runMelt(const QString &target, int realtime = -1);
186  void enqueueAnalysis();
187  void enqueueMelt(const QStringList &targets, int realtime);
188  void encode(const QString &target);
189  void resetOptions();
190  Mlt::Producer *fromProducer(bool usePlaylistBin = false) const;
191  static void filterCodecParams(const QString &vcodec, QStringList &other);
192  void onVideoCodecComboChanged(int index, bool ignorePreset = false, bool resetBframes = true);
193  bool checkForMissingFiles();
194  QString &defaultFormatExtension();
195  void initSpecialCodecLists();
196  void setReframeEnabled(bool enabled);
197  void showResampleWarning(const QString &message);
198  void hideResampleWarning(bool hide = true);
199  void checkFrameRate();
200  void setResolutionAspectFromProfile();
201 };
202 
203 #endif // ENCODEDOCK_H