QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
49 static bool isAvailable();
50
58 QgsVideoExporter( const QString &filename, QSize size, double framesPerSecond );
59 ~QgsVideoExporter() override;
60
69
76
82 double framesPerSecond() const { return mFramesPerSecond; }
83
89 qint64 frameDuration() const { return mFrameDurationUs; }
90
94 QSize size() const { return mSize; }
95
105 void setInputFiles( const QStringList &files );
106
118 void setInputFilesByPattern( const QString &directory, const QString &pattern );
119
125 QStringList inputFiles() const;
126
127#ifndef SIP_RUN
136 void setFileFormat( QMediaFormat::FileFormat format );
137
143 QMediaFormat::FileFormat fileFormat() const;
144
153 void setVideoCodec( QMediaFormat::VideoCodec codec );
154
160 QMediaFormat::VideoCodec videoCodec() const;
161
167 QMediaRecorder::Error error() const;
168#endif
169
170#ifdef SIP_PYQT6_RUN
171
180 void setFileFormat( QMediaFormat::FileFormat format );
181
187 QMediaFormat::FileFormat fileFormat() const;
188
197 void setVideoCodec( QMediaFormat::VideoCodec codec );
198
204 QMediaFormat::VideoCodec videoCodec() const;
205
211 QMediaRecorder::Error error() const;
212#endif
213
219 QString errorString() const;
220
221 public slots:
222
230 void writeVideo() SIP_THROW( QgsNotSupportedException );
231
232 signals:
233
237 void finished();
238
239 private slots:
240
241 void feedFrames();
242 void checkStatus( QMediaRecorder::RecorderState state );
243 void handleError( QMediaRecorder::Error error, const QString &errorString );
244
245 private:
246 QString mFileName;
247 QSize mSize;
248 QStringList mInputFiles;
249 double mFramesPerSecond = 10;
250 qint64 mFrameDurationUs = 100000;
251 QMediaFormat::FileFormat mFormat = QMediaFormat::FileFormat::MPEG4;
252 QMediaFormat::VideoCodec mCodec = QMediaFormat::VideoCodec::H264;
253 QMediaRecorder::Error mError = QMediaRecorder::Error::NoError;
254 int mCurrentFrameIndex = 0;
255 QPointer< QgsFeedback > mFeedback;
256
257 QString mErrorString;
258
259 std::unique_ptr< QMediaCaptureSession > mSession;
260 std::unique_ptr< QMediaRecorder > mRecorder;
261 std::unique_ptr< QVideoFrameInput > mVideoInput;
262};
263
264
265#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:210