QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsvideoexporter.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvideoexporter.h
3 --------------------------
4 begin : November 2025
5 copyright : (C) 2025 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSVIDEOEXPORTER_H
16#define QGSVIDEOEXPORTER_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20
21#include <QObject>
22#include <QPointer>
23#include <QSize>
24#include <QtMultimedia/QMediaFormat>
25#include <QtMultimedia/QMediaRecorder>
26
27class QgsFeedback;
28class QMediaCaptureSession;
29class QVideoFrameInput;
30
41class CORE_EXPORT QgsVideoExporter : public QObject
42{
43 Q_OBJECT
44
45 public:
46
50 static bool isAvailable();
51
59 QgsVideoExporter( const QString &filename, QSize size, double framesPerSecond );
60 ~QgsVideoExporter() override;
61
70
77
83 double framesPerSecond() const { return mFramesPerSecond; }
84
90 qint64 frameDuration() const { return mFrameDurationUs; }
91
95 QSize size() const { return mSize; }
96
106 void setInputFiles( const QStringList &files );
107
119 void setInputFilesByPattern( const QString &directory, const QString &pattern );
120
126 QStringList inputFiles() const;
127
128#ifndef SIP_RUN
137 void setFileFormat( QMediaFormat::FileFormat format );
138
144 QMediaFormat::FileFormat fileFormat() const;
145
154 void setVideoCodec( QMediaFormat::VideoCodec codec );
155
161 QMediaFormat::VideoCodec videoCodec() const;
162
168 QMediaRecorder::Error error() const;
169#endif
170
171#ifdef SIP_PYQT6_RUN
172
181 void setFileFormat( QMediaFormat::FileFormat format );
182
188 QMediaFormat::FileFormat fileFormat() const;
189
198 void setVideoCodec( QMediaFormat::VideoCodec codec );
199
205 QMediaFormat::VideoCodec videoCodec() const;
206
212 QMediaRecorder::Error error() const;
213#endif
214
220 QString errorString() const;
221
222 public slots:
223
231 void writeVideo() SIP_THROW( QgsNotSupportedException );
232
233 signals:
234
238 void finished();
239
240 private slots:
241
242 void feedFrames();
243 void checkStatus( QMediaRecorder::RecorderState state );
244 void handleError( QMediaRecorder::Error error, const QString &errorString );
245
246 private:
247
248 QString mFileName;
249 QSize mSize;
250 QStringList mInputFiles;
251 double mFramesPerSecond = 10;
252 qint64 mFrameDurationUs = 100000;
253 QMediaFormat::FileFormat mFormat = QMediaFormat::FileFormat::MPEG4;
254 QMediaFormat::VideoCodec mCodec = QMediaFormat::VideoCodec::H264;
255 QMediaRecorder::Error mError = QMediaRecorder::Error::NoError;
256 int mCurrentFrameIndex = 0;
257 QPointer< QgsFeedback > mFeedback;
258
259 QString mErrorString;
260
261 std::unique_ptr< QMediaCaptureSession > mSession;
262 std::unique_ptr< QMediaRecorder > mRecorder;
263 std::unique_ptr< QVideoFrameInput > mVideoInput;
264};
265
266
267#endif // QGSVIDEOEXPORTER_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Custom exception class which is raised when an operation is not supported.
void finished()
Emitted when the video export finishes.
QMediaRecorder::Error error() const
Returns the last error received while writing the video.
qint64 frameDuration() const
Returns the duration of each frame, in micro-seconds.
QString errorString() const
Returns the string describing the last error received while writing the video.
QgsVideoExporter(const QString &filename, QSize size, double framesPerSecond)
Constructor for QgsVideoExporter.
double framesPerSecond() const
Returns the output video frames per second.
static bool isAvailable()
Returns true if the video export functionality is available on the current system.
void setFeedback(QgsFeedback *feedback)
Sets an optional feedback object, for progress reports and cancellation support.
QSize size() const
Returns the output video frame size.
QgsFeedback * feedback()
Returns the optional feedback object.
#define SIP_THROW(name,...)
Definition qgis_sip.h:211