PySide6.QtMultimedia.QMediaRecorder¶
- class QMediaRecorder¶
- The - QMediaRecorderclass is used for encoding and recording a capture session. More…- Synopsis¶- Properties¶- actualLocationᅟ- Actual location of the last media content
- durationᅟ- The recorded media duration in milliseconds
- mediaFormatᅟ- This property holds the current QMediaFormat of the recorder
- outputLocationᅟ- Destination location of media content
- recorderStateᅟ- Current state of the media recorder
 - Methods¶- def - __init__()
- def - actualLocation()
- def - addMetaData()
- def - audioBitRate()
- def - autoStop()
- def - captureSession()
- def - duration()
- def - encodingMode()
- def - error()
- def - errorString()
- def - isAvailable()
- def - mediaFormat()
- def - metaData()
- def - outputDevice()
- def - outputLocation()
- def - quality()
- def - recorderState()
- def - setAutoStop()
- def - setMediaFormat()
- def - setMetaData()
- def - setQuality()
- def - videoBitRate()
- def - videoFrameRate()
 - Slots¶- Signals¶
- def - errorChanged()
- def - errorOccurred()
- def - qualityChanged()
 - 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. - Use the - QMediaRecorderclass to encode and record media generated in- QMediaCaptureSession. You can generate:- Audio. Use - QAudioInputor- QAudioBufferInput.
- Video. Use - QCamera,- QScreenCapture,- QWindowCapture, or- QVideoFrameInput.
 - To record media, connect a generator to a corresponding media capture session. - Performance of video encoding and recording is limited by the hardware, the operating system, the installed graphic drivers, and the input video format. If - QCamera,- QScreenCapture, or- QWindowCaptureproduces video frames faster than- QMediaRecordercan encode and record them, the recorder may drop some frames. This is likely to occur if the input frame resolution is high, 4K for example, and hardware-accelerated encoding is unavailable. If you generate input video via- QVideoFrameInput, the method- QVideoFrameInput::sendVideoFramewill do nothing and return- falsewhenever this limitation is reached and the internal frame queue is full. Rely on the signal- QVideoFrameInput::readyToSendVideoFrameto know when the recorder is ready to receive new frames again. If you cannot change the rate of video frame generation and dropping frames is undesirable, we recommend implementing your own frame queue on top of- QVideoFrameInput, considering the memory limitations of the hardware.- 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 - Added 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. - Added 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. - Added 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. - Added in version 6.1. 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- This property holds The actual location of the last media content.. - The actual location is reset when a new - outputLocationor a non-null- outputDeviceis assigned. When- record()is invoked and- outputDeviceis- nullor not writable, the recorder generates the actual location basing on the following rules.- If - outputLocationis empty, a directory, or a file without an extension, the recorder generates the appropriate extension based on the selected media format and system MIME types.
- If - outputLocationis a directory, the recorder generates a new file name within it.
- If - outputLocationis empty, the recorder generates a new file name in the system-specific directory for audio or video.
- The recorder generates the actual location before emitting - recorderStateChanged(RecordingState).
 - Access functions:
 - property audioBitRateᅟ: int¶
 - Access functions:
 - property audioChannelCountᅟ: int¶
 - Access functions:
 - property audioSampleRateᅟ: int¶
 - Access functions:
 - property autoStopᅟ: bool¶
 - This property controls whether the media recorder stops automatically when all media inputs have reported the end of the stream or have been deactivated. - The end of the stream is reported by sending an empty media frame, which you can send explicitly via - QVideoFrameInputor- QAudioBufferInput.- Video inputs, specificly, - QCamera,- QScreenCaptureand- QWindowCapture, can be deactivated via the function- setActive.- Defaults to - false.- QMediaRecorder::autoStop is only supported with the FFmpeg backend. - See also - Access functions:
 - property durationᅟ: int¶
 - This property holds the recorded media duration in milliseconds.. - Access functions:
- Signal - durationChanged()
 
 - property encodingModeᅟ: QMediaRecorder.EncodingMode¶
 - Access functions:
 - property errorᅟ: QMediaRecorder.Error¶
 - Returns the current error state. - See also - Access functions:
- Signal - errorChanged()
 
 - property errorStringᅟ: str¶
 - Returns a string describing the current error state. - See also - Access functions:
- Signal - errorChanged()
 
 - property mediaFormatᅟ: QMediaFormat¶
 - This property holds This property holds the current - QMediaFormatof the recorder..- The value of this property may change when invoking - record(). If this happens, the mediaFormatChanged signal will be emitted. This will always happen if the- audioCodecor- fileFormatproperties are set to unspecified. If a video source (- QCamera,- QScreenCapture, or- QVideoFrameInput) is connected to the- QMediaCaptureSession,- videoCodecmust also be specified. The- audioCodecand- videoCodecproperty values may also change if the media backend does not support the selected file format or codec.- The - fileFormatproperty value may also change to an- audioonly format if a video format was requested, but- QMediaCaptureSessiondoes not have a video source connected. For example, if- fileFormatis set to QMediaFormat::FileFormat::MPEG4, it may be changed to QMediaFormat::FileFormat::Mpeg4Audio.- Applications can determine if mediaFormat will change before recording starts by calling the - isSupported()function. When recording without any video inputs,- record()will not be changed the- QMediaFormatif the following is true:- fileFormatis specified
- audioCodecis specified
- videoCodecis unspecified
- isSupportedreturns- true
 - When recording with video input, mediaFormat will not be changed if the following is true: - fileFormatis specified
- audioCodecis specified
- videoCodecis specified
- isSupportedreturns- true
 - Note - The - QMediaRecorderdoes not take the file name extension from the- outputLocationproperty into account when determining the- fileFormat, and will not adjust the extension of the- outputLocationQUrl to match the selected file format if an extension is specified. Applications should therefore make sure to set the QMediaRecorder::mediaFormat::fileFormat to match the file extension, or not specify a file extension. If no file extension is specified, the- actualLocationfile extension will be updated to match the file format used for recording.- See also - Access functions:
 - property metaDataᅟ: QMediaMetaData¶
 - Returns the metaData associated with the recording. - Access functions:
 - 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, the errorOccured() signal is emitted. - The output location is ignored if a writable - outputDevicehas been assigned to the recorder. This behavior may change in the future, so we recommend setting only one output, either- outputLocationor- outputDevice.- The output location can be empty, a directory, or a file. The path to a directory or file can be relative or absolute. The - record()method generates the actual location according to the specified output location and system-specific settings. Refer to the- actualLocationproperty description for details.- See also - 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:
 - Access functions:
 - Constructs a media recorder. The media recorder is a child of - parent.- Getter of property - actualLocationᅟ.- Signals that the actual - locationof the recorded media has changed. This signal is usually emitted when recording starts.- Notification signal of property - actualLocationᅟ.- addMetaData(metaData)¶
- Parameters:
- metaData – - QMediaMetaData
 
 - Adds - metaDatato the recorded media.- audioBitRate()¶
- Return type:
- int 
 
 - Returns the bit rate of the compressed audio stream in bits per second. - See also - 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. - See also - 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. - See also - Getter of property - audioSampleRateᅟ.- audioSampleRateChanged()¶
 - Signals when the recording audio sample rate changes. - Notification signal of property - audioSampleRateᅟ.- autoStop()¶
- Return type:
- bool 
 - See also 
 - Getter of property - autoStopᅟ.- autoStopChanged()¶
 - Notification signal of property - autoStopᅟ.- captureSession()¶
- Return type:
 
 - Returns the media capture session. - duration()¶
- Return type:
- int 
 
 - Getter of property - durationᅟ.- durationChanged(duration)¶
- Parameters:
- duration – int 
 
 - Signals that the - durationof the recorded media has changed.- Notification signal of property - durationᅟ.- encoderSettingsChanged()¶
- Note - This function is deprecated. 
 - Signals when the encoder settings change. - encodingMode()¶
- Return type:
 
 - Returns the encoding mode. - See also - Getter of property - encodingModeᅟ.- encodingModeChanged()¶
 - Signals when the encoding mode changes. - Notification signal of property - encodingModeᅟ.- Getter of property - errorᅟ.- errorChanged()¶
 - Notification signal of property - errorᅟ.- Signals that an - errorhas occurred, with- errorStringcontaining a description of the error.- errorString()¶
- Return type:
- str 
 
 - Getter of property - errorStringᅟ.- isAvailable()¶
- Return type:
- bool 
 
 - Returns - trueif media recorder service ready to use.- mediaFormat()¶
- Return type:
 - See also 
 - Getter of property - mediaFormatᅟ.- mediaFormatChanged()¶
 - Notification signal of property - mediaFormatᅟ.- metaData()¶
- Return type:
 - See also 
 - 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ᅟ.- Returns the output IO device for media content. - See also - outputLocation()¶
- Return type:
 - See also 
 - 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:
 - See also 
 - Getter of property - qualityᅟ.- qualityChanged()¶
 - Signals when the recording quality changes. - Notification signal of property - qualityᅟ.- record()¶
 - Starts 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.- This method updates - actualLocationaccording to its generation rules.- 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:
 
 - Returns the current media recorder state. - See also - Getter of property - recorderStateᅟ.- recorderStateChanged(state)¶
- Parameters:
- state – - RecorderState
 
 - Signals that a media recorder’s - statehas changed.- Notification signal of property - recorderStateᅟ.- setAudioBitRate(bitRate)¶
- Parameters:
- bitRate – int 
 
 - Sets the audio - bitRatein bits per second.- See also - 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. - See also - Setter of property - audioChannelCountᅟ.- setAudioSampleRate(sampleRate)¶
- Parameters:
- sampleRate – int 
 
 - Sets the audio - sampleRatein Hz.- A value of - -1indicates the recorder should make an optimal choice based on what is available from the audio source, and the limitations of the codec.- See also - Setter of property - audioSampleRateᅟ.- setAutoStop(autoStop)¶
- Parameters:
- autoStop – bool 
 - See also 
 - Setter of property - autoStopᅟ.- setEncodingMode(mode)¶
- Parameters:
- mode – - EncodingMode
 
 - Sets the encoding - modesetting.- If - ConstantQualityEncodingis set, the quality encoding parameter is used and bit rates are ignored, otherwise the bitrates are used.- See also - Setter of property - encodingModeᅟ.- setMediaFormat(format)¶
- Parameters:
- format – - QMediaFormat
 - See also 
 - Setter of property - mediaFormatᅟ.- setMetaData(metaData)¶
- Parameters:
- metaData – - QMediaMetaData
 
 - 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 - Setter of property - metaDataᅟ.- Set the output IO device for media content. - The - devicemust have been opened in the WriteOnly or ReadWrite modes before the recording starts.- The media recorder doesn’t take ownership of the specified - device. If the recording has been started, the device must be kept alive and open until the signal- recorderStateChanged(StoppedState)is emitted.- This method resets - actualLocationimmediately unless the specified- deviceis- null.- If a writable output device is assigned to the recorder, - outputLocationis ignored, and- actualLocationis not generated when recording starts. This behavior may change in the future, so we recommend setting only one output, either- outputLocationor- outputDevice.- QMediaRecorder::setOutputDeviceis only supported with the FFmpeg backend.- See also - Setter of property - outputLocationᅟ.- Setter of property - qualityᅟ.- setVideoBitRate(bitRate)¶
- Parameters:
- bitRate – int 
 
 - Sets the video - bitRatein bits per second.- See also - 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 - Setter of property - 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 - Setter of property - videoResolutionᅟ.- setVideoResolution(width, height)
- Parameters:
- width – int 
- height – int 
 
 
 - Sets the - widthand- heightof 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. - See also - 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. - See also - Getter of property - videoFrameRateᅟ.- videoFrameRateChanged()¶
 - Signals when the recording video frame rate changes. - Notification signal of property - videoFrameRateᅟ.- Returns the resolution of the encoded video. - See also - Getter of property - videoResolutionᅟ.- videoResolutionChanged()¶
 - Signals when the video recording resolution changes. - Notification signal of property - videoResolutionᅟ.