QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
25#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
26#include <QtMultimedia/QMediaFormat>
27#include <QtMultimedia/QMediaRecorder>
28#endif
29
30class QgsFeedback;
31class QMediaCaptureSession;
32class QVideoFrameInput;
33
44class CORE_EXPORT QgsVideoExporter : public QObject
45{
46 Q_OBJECT
47
48 public:
49
53 static bool isAvailable();
54
62 QgsVideoExporter( const QString &filename, QSize size, double framesPerSecond );
63 ~QgsVideoExporter() override;
64
73
80
86 double framesPerSecond() const { return mFramesPerSecond; }
87
93 qint64 frameDuration() const { return mFrameDurationUs; }
94
98 QSize size() const { return mSize; }
99
109 void setInputFiles( const QStringList &files );
110
122 void setInputFilesByPattern( const QString &directory, const QString &pattern );
123
129 QStringList inputFiles() const;
130
131#ifndef SIP_RUN
132#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
133
142 void setFileFormat( QMediaFormat::FileFormat format );
143
149 QMediaFormat::FileFormat fileFormat() const;
150
159 void setVideoCodec( QMediaFormat::VideoCodec codec );
160
166 QMediaFormat::VideoCodec videoCodec() const;
167
173 QMediaRecorder::Error error() const;
174#endif
175#endif
176
177#ifdef SIP_PYQT6_RUN
178
187 void setFileFormat( QMediaFormat::FileFormat format );
188
194 QMediaFormat::FileFormat fileFormat() const;
195
204 void setVideoCodec( QMediaFormat::VideoCodec codec );
205
211 QMediaFormat::VideoCodec videoCodec() const;
212
218 QMediaRecorder::Error error() const;
219#endif
220
226 QString errorString() const;
227
228 public slots:
229
237 void writeVideo() SIP_THROW( QgsNotSupportedException );
238
239 signals:
240
244 void finished();
245
246 private slots:
247
248 void feedFrames();
249#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
250 void checkStatus( QMediaRecorder::RecorderState state );
251 void handleError( QMediaRecorder::Error error, const QString &errorString );
252#endif
253
254 private:
255
256 QString mFileName;
257 QSize mSize;
258 QStringList mInputFiles;
259 double mFramesPerSecond = 10;
260 qint64 mFrameDurationUs = 100000;
261#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
262 QMediaFormat::FileFormat mFormat = QMediaFormat::FileFormat::MPEG4;
263 QMediaFormat::VideoCodec mCodec = QMediaFormat::VideoCodec::H264;
264 QMediaRecorder::Error mError = QMediaRecorder::Error::NoError;
265 int mCurrentFrameIndex = 0;
266#endif
267 QPointer< QgsFeedback > mFeedback;
268
269 QString mErrorString;
270
271#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
272 std::unique_ptr< QMediaCaptureSession > mSession;
273 std::unique_ptr< QMediaRecorder > mRecorder;
274 std::unique_ptr< QVideoFrameInput > mVideoInput;
275#endif
276
277};
278
279
280#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