The QMediaRecorder class is used for encoding and recording a capture session. More...
Header: | #include <QMediaRecorder> |
CMake: | find_package(Qt6 COMPONENTS Multimedia REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
qmake: | QT += multimedia |
Instantiated By: | MediaRecorder |
Inherits: | QObject |
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 } |
QMediaRecorder(QObject *parent = nullptr) | |
virtual | ~QMediaRecorder() |
QUrl | actualLocation() const |
int | audioBitRate() const |
int | audioChannelCount() const |
int | audioSampleRate() 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 |
void | pause() |
void | record() |
void | stop() |
void | actualLocationChanged(const QUrl &location) |
void | durationChanged(qint64 duration) |
void | errorChanged() |
void | errorOccurred(QMediaRecorder::Error error, const QString &errorString) |
void | mediaFormatChanged() |
void | metaDataChanged() |
void | recorderStateChanged(QMediaRecorder::RecorderState state) |
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.setMediaRecorder(&recorder); recorder.setQuality(QMediaRecorder::HighQuality); recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3")); recorder.record();
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. |
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. |
Enumerates quality encoding levels.
Constant | Value |
---|---|
QMediaRecorder::VeryLowQuality |
0 |
QMediaRecorder::LowQuality |
1 |
QMediaRecorder::NormalQuality |
2 |
QMediaRecorder::HighQuality |
3 |
QMediaRecorder::VeryHighQuality |
4 |
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. |
[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) |
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) |
[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) |
Constructs a media recorder which records the media produced by a microphone and camera. The media recorder is a child of parent.
[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.
[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::errorOccurred(QMediaRecorder::Error error, const QString &errorString)
Signals that an error has occurred, with errorString containing a description of the error.
[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.
[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.
[signal]
void QMediaRecorder::recorderStateChanged(QMediaRecorder::RecorderState state)
Signals that a media recorder's state has changed.
Note: Notifier signal for property recorderState.
[slot]
void QMediaRecorder::stop()
Stops recording.
The recorder state is changed to QMediaRecorder::StoppedState.
[virtual]
QMediaRecorder::~QMediaRecorder()
Destroys a media recorder object.
Returns the bit rate of the compressed audio stream in bits per second.
See also setAudioBitRate().
Returns the number of audio channels.
See also setAudioChannelCount().
Returns the audio sample rate in Hz.
See also setAudioSampleRate().
Returns the encoding mode.
See also setEncodingMode() and EncodingMode.
Returns the current error state.
Note: Getter function for property error.
See also errorString().
Returns a string describing the current error state.
Note: Getter function for property errorString.
See also error().
Returns true
if media recorder service ready to use.
Returns the metaData associated with the recording.
Note: Getter function for property metaData.
See also setMetaData().
Returns the current media recorder state.
Note: Getter function for property recorderState.
See also QMediaRecorder::RecorderState.
Sets the audio bitRate in bits per second.
See also audioBitRate().
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().
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().
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.
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().
Sets the video bitRate in bits per second.
See also videoBitRate().
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().
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().
Sets the width and height of the resolution of the encoded video.
This is an overloaded function.
Returns the bit rate of the compressed video stream in bits per second.
See also setVideoBitRate().
Returns the video frame rate.
See also setVideoFrameRate().
Returns the resolution of the encoded video.
See also setVideoResolution().
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.2/qmediarecorder.html