class QMediaRecorder#

The QMediaRecorder class is used for encoding and recording a capture session. More

Inheritance diagram of PySide6.QtMultimedia.QMediaRecorder

Synopsis#

Properties#

Methods#

Slots#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

The QMediaRecorder class is a class for encoding and recording media generated in a QMediaCaptureSession .

session = QMediaCaptureSession()
audioInput = QAudioInput()
session.setAudioInput(input)
recorder = QMediaRecorder()
session.setRecorder(recorder)
recorder.setQuality(QMediaRecorder.HighQuality)
recorder.setOutputLocation(QUrl.fromLocalFile("test.mp3"))
recorder.record()
class Quality#

Enumerates quality encoding levels.

Constant

Description

QMediaRecorder.VeryLowQuality

QMediaRecorder.LowQuality

QMediaRecorder.NormalQuality

QMediaRecorder.HighQuality

QMediaRecorder.VeryHighQuality

New in version 6.1.

class EncodingMode#

Enumerates encoding modes.

Constant

Description

QMediaRecorder.ConstantQualityEncoding

Encoding will aim to have a constant quality, adjusting bitrate to fit.

QMediaRecorder.ConstantBitRateEncoding

Encoding will use a constant bit rate, adjust quality to fit.

QMediaRecorder.AverageBitRateEncoding

Encoding will try to keep an average bitrate setting, but will use more or less as needed.

QMediaRecorder.TwoPassEncoding

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.

New in version 6.1.

class RecorderState#

Constant

Description

QMediaRecorder.StoppedState

The recorder is not active.

QMediaRecorder.RecordingState

The recording is requested.

QMediaRecorder.PausedState

The recorder is paused.

New in version 6.1.

class Error#

Constant

Description

QMediaRecorder.NoError

No Errors.

QMediaRecorder.ResourceError

Device is not ready or not available.

QMediaRecorder.FormatError

Current format is not supported.

QMediaRecorder.OutOfSpaceError

No space left on device.

QMediaRecorder.LocationNotWritable

The output location is not writable.

New in version 6.1.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property actualLocationᅟ: 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:
property audioBitRateᅟ: int#
Access functions:
property audioChannelCountᅟ: int#
Access functions:
property audioSampleRateᅟ: int#
Access functions:
property durationᅟ: int#

This property holds the recorded media duration in milliseconds..

Access functions:
property encodingModeᅟ: QMediaRecorder.EncodingMode#
Access functions:
property errorᅟ: QMediaRecorder.Error#

Returns the current error state.

See also

errorString()

Access functions:
property errorStringᅟ: str#

Returns a string describing the current error state.

See also

error()

Access functions:
property mediaFormatᅟ: QMediaFormat#

Returns the recording media format.

Access functions:
property metaDataᅟ: QMediaMetaData#

Returns the metaData associated with the recording.

Access functions:
property 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:
property qualityᅟ: QMediaRecorder.Quality#

Returns the recording quality.

Access functions:
property recorderStateᅟ: 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:
property videoBitRateᅟ: int#
Access functions:
property videoFrameRateᅟ: float#
Access functions:
property videoResolutionᅟ: QSize#
Access functions:
__init__([parent=None])#
Parameters:

parentQObject

Constructs a media recorder which records the media produced by a microphone and camera. The media recorder is a child of parent.

actualLocation()#
Return type:

QUrl

Getter of property actualLocationᅟ .

actualLocationChanged(location)#
Parameters:

locationQUrl

Signals that the actual location of the recorded media has changed. This signal is usually emitted when recording starts.

Notification signal of property actualLocationᅟ .

addMetaData(metaData)#
Parameters:

metaDataQMediaMetaData

Adds metaData to the recorded media.

audioBitRate()#
Return type:

int

Returns the bit rate of the compressed audio stream in bits per second.

Getter of property audioBitRateᅟ .

audioBitRateChanged()#

Signals when the recording audio bit rate changes.

Notification signal of property audioBitRateᅟ .

audioChannelCount()#
Return type:

int

Returns the number of audio channels.

Getter of property audioChannelCountᅟ .

audioChannelCountChanged()#

Signals when the recording audio channel count changes.

Notification signal of property audioChannelCountᅟ .

audioSampleRate()#
Return type:

int

Returns the audio sample rate in Hz.

Getter of property audioSampleRateᅟ .

audioSampleRateChanged()#

Signals when the recording audio sample rate changes.

Notification signal of property audioSampleRateᅟ .

captureSession()#
Return type:

QMediaCaptureSession

Returns the media capture session.

duration()#
Return type:

int

Getter of property durationᅟ .

durationChanged(duration)#
Parameters:

duration – int

Signals that the duration of the recorded media has changed.

Notification signal of property durationᅟ .

encoderSettingsChanged()#

Signals when the encoder settings change.

encodingMode()#
Return type:

EncodingMode

Returns the encoding mode.

Getter of property encodingModeᅟ .

encodingModeChanged()#

Signals when the encoding mode changes.

Notification signal of property encodingModeᅟ .

error()#
Return type:

Error

Getter of property errorᅟ .

errorChanged()#

Notification signal of property errorᅟ .

errorOccurred(error, errorString)#
Parameters:
  • errorError

  • errorString – str

Signals that an error has occurred, with errorString containing a description of the error.

errorString()#
Return type:

str

Getter of property errorStringᅟ .

isAvailable()#
Return type:

bool

Returns true if media recorder service ready to use.

mediaFormat()#
Return type:

QMediaFormat

See also

setMediaFormat()

Getter of property mediaFormatᅟ .

mediaFormatChanged()#

Notification signal of property mediaFormatᅟ .

metaData()#
Return type:

QMediaMetaData

See also

setMetaData()

Getter of property metaDataᅟ .

metaDataChanged()#

Signals that a media object’s meta-data has changed.

If multiple meta-data elements are changed metaDataChanged() is emitted once.

Notification signal of property metaDataᅟ .

outputLocation()#
Return type:

QUrl

Getter of property outputLocationᅟ .

pause()#

Pauses recording.

The recorder state is changed to PausedState .

Depending on the platform, pausing recording may be not supported. In this case the recorder state is unchanged.

quality()#
Return type:

Quality

See also

setQuality()

Getter of property qualityᅟ .

qualityChanged()#

Signals when the recording quality changes.

Notification signal of property qualityᅟ .

record()#

Start recording.

While the recorder state is changed immediately to c{ 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.

recorderState()#
Return type:

RecorderState

Returns the current media recorder state.

See also

RecorderState

Getter of property recorderStateᅟ .

recorderStateChanged(state)#
Parameters:

stateRecorderState

Signals that a media recorder’s state has changed.

Notification signal of property recorderStateᅟ .

setAudioBitRate(bitRate)#
Parameters:

bitRate – int

Sets the audio bitRate in bits per second.

See also

audioBitRate()

Setter of property audioBitRateᅟ .

setAudioChannelCount(channels)#
Parameters:

channels – int

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.

Setter of property audioChannelCountᅟ .

setAudioSampleRate(sampleRate)#
Parameters:

sampleRate – int

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.

Setter of property audioSampleRateᅟ .

setEncodingMode(arg__1)#
Parameters:

arg__1EncodingMode

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.

Setter of property encodingModeᅟ .

setMediaFormat(format)#
Parameters:

formatQMediaFormat

See also

mediaFormat()

Setter of property mediaFormatᅟ .

setMetaData(metaData)#
Parameters:

metaDataQMediaMetaData

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.

See also

metaData()

Setter of property metaDataᅟ .

setOutputLocation(location)#
Parameters:

locationQUrl

See also

outputLocation()

Setter of property outputLocationᅟ .

setQuality(quality)#
Parameters:

qualityQuality

See also

quality()

Setter of property qualityᅟ .

setVideoBitRate(bitRate)#
Parameters:

bitRate – int

Sets the video bitRate in bits per second.

See also

videoBitRate()

Setter of property videoBitRateᅟ .

setVideoFrameRate(frameRate)#
Parameters:

frameRate – float

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()

Setter of property videoFrameRateᅟ .

setVideoResolution(arg__1)#
Parameters:

arg__1QSize

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.

Setter of property videoResolutionᅟ .

setVideoResolution(width, height)
Parameters:
  • width – int

  • height – int

Sets the width and height of the resolution of the encoded video.

This is an overloaded function.

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 StoppedState .

videoBitRate()#
Return type:

int

Returns the bit rate of the compressed video stream in bits per second.

Getter of property videoBitRateᅟ .

videoBitRateChanged()#

Signals when the recording video bit rate changes.

Notification signal of property videoBitRateᅟ .

videoFrameRate()#
Return type:

float

Returns the video frame rate.

Getter of property videoFrameRateᅟ .

videoFrameRateChanged()#

Signals when the recording video frame rate changes.

Notification signal of property videoFrameRateᅟ .

videoResolution()#
Return type:

QSize

Returns the resolution of the encoded video.

Getter of property videoResolutionᅟ .

videoResolutionChanged()#

Signals when the video recording resolution changes.

Notification signal of property videoResolutionᅟ .