MediaRecorder QML 类型

要编码和录制的媒体生成于 CaptureSession . 更多...

import 语句: import QtMultimedia
在 C++: QMediaRecorder

特性

信号

方法

详细描述

Use the MediaRecorder element within a CaptureSession to encode and record:

  • Audio captured from an audio interface (like microphone or line input).
  • Video captured from camera, screen, or an application window.

Performance of video encoding and recording is limited by the hardware, the operating system, the installed graphic drivers, and the input video format. If Camera , ScreenCapture ,或 WindowCapture produces video frames faster than MediaRecorder can 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.

The code below shows a simple capture session containing a MediaRecorder using the default camera and default audio input.

CaptureSession {
    id: captureSession
    camera: Camera {
        id: camera
        active: true
    }
    audioInput: AudioInput {}
    recorder: MediaRecorder {
        id: recorder
    }
}
					

The code below shows how the recording can be started and stopped.

CameraButton {
    text: "Record"
    visible: recorder.recorderState !== MediaRecorder.RecordingState
    onClicked: recorder.record()
}
CameraButton {
    id: stopButton
    text: "Stop"
    visible: recorder.recorderState === MediaRecorder.RecordingState
    onClicked: recorder.stop()
}
					

另请参阅 CaptureSession , Camera , ScreenCapture , WindowCapture , AudioInput ,和 ImageCapture .

特性文档编制

actualLocation : url [read-only]

The actual location of the last media content.

The actual location is reset when a new outputLocation is assigned. When record () is invoked, the recorder generates the actual location basing on the following rules.

  • outputLocation is 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.
  • outputLocation is a directory, the recorder generates a new file name within it.
  • outputLocation is 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) .

audioBitRate : int [since 6.6]

This property holds the bit rate of the compressed audio stream in bits per second.

该特性在 Qt 6.6 引入。

audioChannelCount : int [since 6.6]

This property holds the number of audio channels.

该特性在 Qt 6.6 引入。

audioSampleRate : int [since 6.6]

This property holds the audio sample rate in Hz.

该特性在 Qt 6.6 引入。

duration : qint64 [read-only]

此特性保持录制媒体的持续时间 (以毫秒为单位)。

encodingMode : enumeration [since 6.6]

This property holds the encoding mode.

该特性在 Qt 6.6 引入。

另请参阅 QMediaRecorder::EncodingMode .

error : enumeration [read-only]

This property holds the current media recorder error state.

常量 描述
MediaRecorder.NoError Not in an error state.
MediaRecorder.ResourceError Not enough system resources
MediaRecorder.FormatError the current format is not supported.
MediaRecorder.OutOfSpaceError 设备没有剩余空间。
MediaRecorder.LocationNotWriteable 输出位置不可写。

errorString : string [read-only]

This property holds a string describing the current error state.

另请参阅 error .

mediaFormat : mediaFormat

This property holds the current MediaFormat of the recorder.

metaData : mediaMetaData

This property holds meta data associated with the recording.

When a recording is started, any meta-data assigned will be attached to that recording.

注意: Ensure that meta-data is assigned correctly by assigning it before starting the recording.

另请参阅 mediaMetaData .

outputLocation : url

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 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 actualLocation property description for details.

另请参阅 actualLocation and errorOccurred ().

quality : enumeration

枚举品质编码级别。

常量
MediaRecorder.VeryLowQuality
MediaRecorder.LowQuality
MediaRecorder.NormalQuality
MediaRecorder.HighQuality
MediaRecorder.VeryHighQuality

recorderState : enumeration [read-only]

This property holds the current media recorder state.

The state property represents the user request and is changed synchronously during record (), pause () 或 stop () calls. RecorderSstate may also change asynchronously when recording fails.

常量 描述
MediaRecorder.StoppedState 录制器不活动。
MediaRecorder.RecordingState 请求录制。
MediaRecorder.PausedState The recorder is pause.

videoBitRate : int [since 6.6]

This property holds the bit rate of the compressed video stream in bits per second.

该特性在 Qt 6.6 引入。

videoFrameRate : real [since 6.6]

This property holds the video frame rate.

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.

该特性在 Qt 6.6 引入。

videoResolution : Size [since 6.6]

This property holds the resolution of the encoded video.

Set an empty Size to make the recorder choose an optimal resolution based on what is available from the video source and the limitations of the codec.

该特性在 Qt 6.6 引入。

信号文档编制

actualLocationChanged (const QUrl & location )

Signals that the actual location of the recorded media has changed.

This signal is usually emitted when recording starts.

注意: 相应处理程序是 onActualLocationChanged .

durationChanged ( qint64 duration )

发射信号,当 duration of the recorded media has changed.

注意: 相应处理程序是 onDurationChanged .

errorOccurred ( Error error , const QString & errorString )

发射信号,当 error has occurred.

The errorString contains a description of the error.

注意: 相应处理程序是 onErrorOccurred .

metaDataChanged ()

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

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

注意: 相应处理程序是 onMetaDataChanged .

recorderStateChanged ( RecorderState state )

Signals that a media recorder's state 已改变。

注意: 相应处理程序是 onRecorderStateChanged .

方法文档编制

pause ()

暂停录制。

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.

record ()

Starts recording.

While the recorder state is changed immediately to MediaRecorder.RecordingState , recording may start asynchronously.

If recording fails, the error() signal is emitted with recorder state being reset back to QMediaRecorder.StoppedState .

This method updates actualLocation according to its generation rules.

注意: 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 the Window and unlock it again once the recording is finished.

stop ()

Stops the recording.

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 .

内容

  1. 特性

  2. 信号

  3. 方法

  4. 详细描述