QMediaRecorder Class▲
-
Header: QMediaRecorder
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
-
qmake: QT += multimedia
-
Inherited By:
-
Instantiated By: qml-qtmultimedia-mediarecorder.xml
-
Inherits: QObject
-
Group: QMediaRecorder is part of multimedia, multimedia_recording, multimedia_video, multimedia_audio
Detailed Description▲
The QMediaRecorder class is a class for encoding and recording media generated in a QMediaCaptureSession.
QMediaCaptureSession session;
QAudioInput audioInput;
session.setAudioInput(&
amp;input);
QMediaRecorder recorder;
session.setRecorder(&
amp;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 |
|
---|---|
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:
-
actualLocation() const
Notifier signal:
-
void actualLocationChanged(const &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)
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:
-
outputLocation() const
-
void setOutputLocation(const &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:
-
recorderState() const
Notifier signal:
-
void recorderStateChanged( 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.
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.
Notifier signal for property actualLocation.
int QMediaRecorder::audioBitRate() const▲
Returns the bit rate of the compressed audio stream in bits per second.
See Also▲
See also setAudioBitRate()
int QMediaRecorder::audioChannelCount() const▲
int QMediaRecorder::audioSampleRate() const▲
void QMediaRecorder::durationChanged(qint64 duration)▲
Signals that the duration of the recorded media has changed.
Notifier signal for property duration.
QMediaRecorder::EncodingMode QMediaRecorder::encodingMode() const▲
QMediaRecorder::Error QMediaRecorder::error() const▲
Returns the current error state.
Getter function for property error.
See Also▲
See also errorString()
void QMediaRecorder::errorOccurred(QMediaRecorder::Error error, const QString &errorString)▲
Signals that an error has occurred, with errorString containing a description of the error.
QString QMediaRecorder::errorString() const▲
Returns a string describing the current error state.
Getter function for property errorString.
See Also▲
See also error()
bool QMediaRecorder::isAvailable() const▲
Returns true if media recorder service ready to use.
QMediaMetaData QMediaRecorder::metaData() const▲
Returns the metaData associated with the recording.
Getter function for property metaData.
See Also▲
See also setMetaData()
void QMediaRecorder::metaDataChanged()▲
Signals that a media object's meta-data has changed.
If multiple meta-data elements are changed metaDataChanged() is emitted once.
Notifier signal for property metaData.
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.
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.
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.
Getter function for property recorderState.
See Also▲
See also QMediaRecorder::RecorderState
void QMediaRecorder::recorderStateChanged(QMediaRecorder::RecorderState state)▲
Signals that a media recorder's state has changed.
Notifier signal for property recorderState.
void QMediaRecorder::setAudioBitRate(int bitRate)▲
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▲
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▲
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▲
See also encodingMode(), EncodingMode
void QMediaRecorder::setMetaData(const QMediaMetaData &metaData)▲
Sets the meta data to metaData.
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.
Setter function for property metaData.
See Also▲
See also metaData()
void QMediaRecorder::setVideoBitRate(int bitRate)▲
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▲
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▲
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.
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▲
See also setVideoBitRate()