QMediaRecorder Class
The QMediaRecorder class is used for encoding and recording a capture session. More...
Header: | #include <QMediaRecorder> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Multimedia) target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
qmake: | QT += multimedia |
Instantiated By: | MediaRecorder |
Inherits: | QObject |
Public Types
enum | EncodingMode { ConstantQualityEncoding, ConstantBitRateEncoding, AverageBitRateEncoding, TwoPassEncoding } |
enum | Error { NoError, ResourceError, FormatError, OutOfSpaceError, LocationNotWritable } |
enum | Quality { VeryLowQuality, LowQuality, NormalQuality, HighQuality, VeryHighQuality } |
enum | RecorderState { StoppedState, RecordingState, PausedState } |
Properties
|
|
Public Functions
QMediaRecorder(QObject *parent = nullptr) | |
virtual | ~QMediaRecorder() |
QUrl | actualLocation() const |
void | addMetaData(const QMediaMetaData &metaData) |
int | audioBitRate() const |
int | audioChannelCount() const |
int | audioSampleRate() const |
QMediaCaptureSession * | captureSession() const |
qint64 | duration() const |
QMediaRecorder::EncodingMode | encodingMode() const |
QMediaRecorder::Error | error() const |
QString | errorString() const |
bool | isAvailable() const |
QMediaFormat | mediaFormat() const |
QMediaMetaData | metaData() const |
QUrl | outputLocation() const |
QMediaRecorder::Quality | quality() const |
QMediaRecorder::RecorderState | recorderState() const |
void | setAudioBitRate(int bitRate) |
void | setAudioChannelCount(int channels) |
void | setAudioSampleRate(int sampleRate) |
void | setEncodingMode(QMediaRecorder::EncodingMode mode) |
void | setMediaFormat(const QMediaFormat &format) |
void | setMetaData(const QMediaMetaData &metaData) |
void | setOutputLocation(const QUrl &location) |
void | setQuality(QMediaRecorder::Quality quality) |
void | setVideoBitRate(int bitRate) |
void | setVideoFrameRate(qreal frameRate) |
void | setVideoResolution(const QSize &size) |
void | setVideoResolution(int width, int height) |
int | videoBitRate() const |
qreal | videoFrameRate() const |
QSize | videoResolution() const |
Public Slots
Signals
void | actualLocationChanged(const QUrl &location) |
void | audioBitRateChanged() |
void | audioChannelCountChanged() |
void | audioSampleRateChanged() |
void | durationChanged(qint64 duration) |
void | encoderSettingsChanged() |
void | encodingModeChanged() |
void | errorChanged() |
void | errorOccurred(QMediaRecorder::Error error, const QString &errorString) |
void | mediaFormatChanged() |
void | metaDataChanged() |
void | qualityChanged() |
void | recorderStateChanged(QMediaRecorder::RecorderState state) |
void | videoBitRateChanged() |
void | videoFrameRateChanged() |
void | videoResolutionChanged() |
Detailed Description
The QMediaRecorder class is a class for encoding and recording media generated in a QMediaCaptureSession.
QMediaCaptureSession session; QAudioInput audioInput; session.setAudioInput(&input); QMediaRecorder recorder; session.setRecorder(&recorder); recorder.setQuality(QMediaRecorder::HighQuality); recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3")); recorder.record();
Member Type Documentation
enum QMediaRecorder::EncodingMode
Enumerates encoding modes.
Constant | Value | Description |
---|---|---|
QMediaRecorder::ConstantQualityEncoding | 0 | Encoding will aim to have a constant quality, adjusting bitrate to fit. |
QMediaRecorder::ConstantBitRateEncoding | 1 | Encoding will use a constant bit rate, adjust quality to fit. |
QMediaRecorder::AverageBitRateEncoding | 2 | Encoding will try to keep an average bitrate setting, but will use more or less as needed. |
QMediaRecorder::TwoPassEncoding | 3 | The media will first be processed to determine the characteristics, and then processed a second time allocating more bits to the areas that need it. |
enum QMediaRecorder::Error
Constant | Value | Description |
---|---|---|
QMediaRecorder::NoError | 0 | No Errors. |
QMediaRecorder::ResourceError | 1 | Device is not ready or not available. |
QMediaRecorder::FormatError | 2 | Current format is not supported. |
QMediaRecorder::OutOfSpaceError | 3 | No space left on device. |
QMediaRecorder::LocationNotWritable | 4 | The output location is not writable. |
enum QMediaRecorder::Quality
Enumerates quality encoding levels.
Constant | Value |
---|---|
QMediaRecorder::VeryLowQuality | 0 |
QMediaRecorder::LowQuality | 1 |
QMediaRecorder::NormalQuality | 2 |
QMediaRecorder::HighQuality | 3 |
QMediaRecorder::VeryHighQuality | 4 |
enum QMediaRecorder::RecorderState
Constant | Value | Description |
---|---|---|
QMediaRecorder::StoppedState | 0 | The recorder is not active. |
QMediaRecorder::RecordingState | 1 | The recording is requested. |
QMediaRecorder::PausedState | 2 | The recorder is paused. |
Property Documentation
[read-only]
actualLocation : const QUrl
This property holds the actual location of the last media content.
The actual location is usually available after recording starts, and reset when new location is set or new recording starts.
Access functions:
QUrl | actualLocation() const |
Notifier signal:
void | actualLocationChanged(const QUrl &location) |
[read-only]
duration : const qint64
This property holds the recorded media duration in milliseconds.
Access functions:
qint64 | duration() const |
Notifier signal:
void | durationChanged(qint64 duration) |
[read-only]
error : const QMediaRecorder::Error
Returns the current error state.
Access functions:
QMediaRecorder::Error | error() const |
Notifier signal:
void | errorChanged() |
See also errorString().
[read-only]
errorString : const QString
Returns a string describing the current error state.
Access functions:
QString | errorString() const |
Notifier signal:
void | errorChanged() |
See also error().
mediaFormat : QMediaFormat
Returns the recording media format.
Access functions:
QMediaFormat | mediaFormat() const |
void | setMediaFormat(const QMediaFormat &format) |
Notifier signal:
void | mediaFormatChanged() |
metaData : QMediaMetaData
Returns the metaData associated with the recording.
Access functions:
QMediaMetaData | metaData() const |
void | setMetaData(const QMediaMetaData &metaData) |
Notifier signal:
void | metaDataChanged() |
outputLocation : QUrl
This property holds the destination location of media content.
Setting the location can fail, for example when the service supports only local file system locations but a network URL was passed. If the operation fails an errorOccured() signal is emitted.
The output location can be relative or empty; in the latter case the recorder uses the system specific place and file naming scheme.
Access functions:
QUrl | outputLocation() const |
void | setOutputLocation(const QUrl &location) |
quality : Quality
Returns the recording quality.
Access functions:
QMediaRecorder::Quality | quality() const |
void | setQuality(QMediaRecorder::Quality quality) |
[read-only]
recorderState : const QMediaRecorder::RecorderState
This property holds the current state of the media recorder.
The state property represents the user request and is changed synchronously during record(), pause() or stop() calls. Recorder state may also change asynchronously when recording fails.
Access functions:
QMediaRecorder::RecorderState | recorderState() const |
Notifier signal:
void | recorderStateChanged(QMediaRecorder::RecorderState state) |
Member Function Documentation
QMediaRecorder::QMediaRecorder(QObject *parent = nullptr)
Constructs a media recorder which records the media produced by a microphone and camera. The media recorder is a child of parent.
[virtual]
QMediaRecorder::~QMediaRecorder()
Destroys a media recorder object.
[signal]
void QMediaRecorder::actualLocationChanged(const QUrl &location)
Signals that the actual location of the recorded media has changed. This signal is usually emitted when recording starts.
Note: Notifier signal for property actualLocation.
void QMediaRecorder::addMetaData(const QMediaMetaData &metaData)
Adds metaData to the recorded media.
int QMediaRecorder::audioBitRate() const
Returns the bit rate of the compressed audio stream in bits per second.
See also setAudioBitRate().
[signal]
void QMediaRecorder::audioBitRateChanged()
Signals when the recording audio bit rate changes.
int QMediaRecorder::audioChannelCount() const
Returns the number of audio channels.
See also setAudioChannelCount().
[signal]
void QMediaRecorder::audioChannelCountChanged()
Signals when the recording audio channel count changes.
int QMediaRecorder::audioSampleRate() const
Returns the audio sample rate in Hz.
See also setAudioSampleRate().
[signal]
void QMediaRecorder::audioSampleRateChanged()
Signals when the recording audio sample rate changes.
QMediaCaptureSession *QMediaRecorder::captureSession() const
Returns the media capture session.
[signal]
void QMediaRecorder::durationChanged(qint64 duration)
Signals that the duration of the recorded media has changed.
Note: Notifier signal for property duration.
[signal]
void QMediaRecorder::encoderSettingsChanged()
Signals when the encoder settings change.
QMediaRecorder::EncodingMode QMediaRecorder::encodingMode() const
Returns the encoding mode.
See also setEncodingMode() and EncodingMode.
[signal]
void QMediaRecorder::encodingModeChanged()
Signals when the encoding mode changes.
[signal]
void QMediaRecorder::errorOccurred(QMediaRecorder::Error error, const QString &errorString)
Signals that an error has occurred, with errorString containing a description of the error.
bool QMediaRecorder::isAvailable() const
Returns true
if media recorder service ready to use.
[signal]
void QMediaRecorder::metaDataChanged()
Signals that a media object's meta-data has changed.
If multiple meta-data elements are changed metaDataChanged() is emitted once.
Note: Notifier signal for property metaData.
[slot]
void QMediaRecorder::pause()
Pauses recording.
The recorder state is changed to QMediaRecorder::PausedState.
Depending on the platform, pausing recording may be not supported. In this case the recorder state is unchanged.
[signal]
void QMediaRecorder::qualityChanged()
Signals when the recording quality changes.
[slot]
void QMediaRecorder::record()
Start recording.
While the recorder state is changed immediately to c{QMediaRecorder::RecordingState}, recording may start asynchronously.
If recording fails error() signal is emitted with recorder state being reset back to QMediaRecorder::StoppedState
.
Note: On mobile devices, recording will happen in the orientation the device had when calling record and is locked for the duration of the recording. To avoid artifacts on the user interface, we recommend to keep the user interface locked to the same orientation as long as the recording is ongoing using the contentOrientation property of QWindow and unlock it again once the recording is finished.
QMediaRecorder::RecorderState QMediaRecorder::recorderState() const
Returns the current media recorder state.
Note: Getter function for property recorderState.
See also QMediaRecorder::RecorderState.
[signal]
void QMediaRecorder::recorderStateChanged(QMediaRecorder::RecorderState state)
Signals that a media recorder's state has changed.
Note: Notifier signal for property recorderState.
void QMediaRecorder::setAudioBitRate(int bitRate)
Sets the audio bitRate in bits per second.
See also audioBitRate().
void QMediaRecorder::setAudioChannelCount(int channels)
Sets the number of audio channels.
A value of -1 indicates the recorder should make an optimal choice based on what is available from the audio source and the limitations of the codec.
See also audioChannelCount().
void QMediaRecorder::setAudioSampleRate(int sampleRate)
Sets the audio sampleRate in Hz.
A value of -1
indicates the recorder should make an optimal choice based on what is available from the audio source, and the limitations of the codec.
See also audioSampleRate().
void QMediaRecorder::setEncodingMode(QMediaRecorder::EncodingMode mode)
Sets the encoding mode setting.
If ConstantQualityEncoding is set, the quality encoding parameter is used and bit rates are ignored, otherwise the bitrates are used.
See also encodingMode() and EncodingMode.
void QMediaRecorder::setMetaData(const QMediaMetaData &metaData)
Sets the meta data to metaData.
Note: To ensure that meta-data is set correctly, it should be set before starting the recording. Once the recording is started, any meta-data set will be attached to the next recording.
Note: Setter function for property metaData.
See also metaData().
void QMediaRecorder::setVideoBitRate(int bitRate)
Sets the video bitRate in bits per second.
See also videoBitRate().
void QMediaRecorder::setVideoFrameRate(qreal frameRate)
Sets the video frameRate.
A value of 0 indicates the recorder should make an optimal choice based on what is available from the video source and the limitations of the codec.
See also videoFrameRate().
void QMediaRecorder::setVideoResolution(const QSize &size)
Sets the resolution of the encoded video to size.
Pass an empty QSize to make the recorder choose an optimal resolution based on what is available from the video source and the limitations of the codec.
See also videoResolution().
void QMediaRecorder::setVideoResolution(int width, int height)
Sets the width and height of the resolution of the encoded video.
This is an overloaded function.
[slot]
void QMediaRecorder::stop()
The recorder will stop the recording. Processing pending video and audio data might however still take some time. The recording is finished, once the state of the media recorder changes to QMediaRecorder::StoppedState.
int QMediaRecorder::videoBitRate() const
Returns the bit rate of the compressed video stream in bits per second.
See also setVideoBitRate().
[signal]
void QMediaRecorder::videoBitRateChanged()
Signals when the recording video bit rate changes.
qreal QMediaRecorder::videoFrameRate() const
Returns the video frame rate.
See also setVideoFrameRate().
[signal]
void QMediaRecorder::videoFrameRateChanged()
Signals when the recording video frame rate changes.
QSize QMediaRecorder::videoResolution() const
Returns the resolution of the encoded video.
See also setVideoResolution().
[signal]
void QMediaRecorder::videoResolutionChanged()
Signals when the video recording resolution changes.
© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.