The QMediaRecorder class is used for encoding and recording a capture session. 更多...
| 頭: | #include <QMediaRecorder> |
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
| qmake: | QT += multimedia |
| 實例化: | MediaRecorder |
| 繼承: | 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 |
| void | addMetaData (const QMediaMetaData & metaData ) |
| int | audioBitRate () const |
| int | audioChannelCount () const |
| int | audioSampleRate () const |
| QMediaCaptureSession * | captureSession () 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 | audioBitRateChanged () |
| void | audioChannelCountChanged () |
| void | audioSampleRateChanged () |
| void | durationChanged (qint64 duration ) |
| void | encoderSettingsChanged () |
| void | encodingModeChanged () |
| void | errorChanged () |
| void | errorOccurred (QMediaRecorder::Error error , const QString & errorString ) |
| void | mediaFormatChanged () |
| void | metaDataChanged () |
| void | qualityChanged () |
| void | recorderStateChanged (QMediaRecorder::RecorderState state ) |
| void | videoBitRateChanged () |
| void | videoFrameRateChanged () |
| void | videoResolutionChanged () |
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.setRecorder(&recorder); recorder.setQuality(QMediaRecorder::HighQuality); recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3")); recorder.record();
枚舉編碼模式。
| 常量 | 值 | 描述 |
|---|---|---|
QMediaRecorder::ConstantQualityEncoding
|
0
|
編碼的目標是擁有常量品質,調節比特率以擬閤。 |
QMediaRecorder::ConstantBitRateEncoding
|
1
|
編碼將使用常量比特率,調節品質以擬閤。 |
QMediaRecorder::AverageBitRateEncoding
|
2
|
編碼將試著保持平均比特率設置,但會根據需要使用更多 (或更少)。 |
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. |
| 常量 | 值 | 描述 |
|---|---|---|
QMediaRecorder::NoError
|
0
|
沒有錯誤。 |
QMediaRecorder::ResourceError
|
1
|
設備未就緒 (或不可用)。 |
QMediaRecorder::FormatError
|
2
|
不支持當前格式。 |
QMediaRecorder::OutOfSpaceError
|
3
|
設備沒有剩餘空間。 |
QMediaRecorder::LocationNotWritable
|
4
|
The output location is not writable. |
枚舉品質編碼級彆。
| 常量 | 值 |
|---|---|
QMediaRecorder::VeryLowQuality
|
0
|
QMediaRecorder::LowQuality
|
1
|
QMediaRecorder::NormalQuality
|
2
|
QMediaRecorder::HighQuality
|
3
|
QMediaRecorder::VeryHighQuality
|
4
|
| 常量 | 值 | 描述 |
|---|---|---|
QMediaRecorder::StoppedState
|
0
|
The recorder is not active. |
QMediaRecorder::RecordingState
|
1
|
請求錄製。 |
QMediaRecorder::PausedState
|
2
|
錄製器暫停。 |
[read-only]
actualLocation
: const
QUrl
此特性保持最後媒體內容的實際位置。
The actual location is usually available after recording starts, and reset when new location is set or new recording starts.
訪問函數:
| QUrl | actualLocation () const |
通知程序信號:
| void | actualLocationChanged (const QUrl & location ) |
[read-only]
duration
: const
qint64
此特性保持錄製媒體的持續時間 (以毫秒為單位)。
訪問函數:
| qint64 | duration () const |
通知程序信號:
| void | durationChanged (qint64 duration ) |
[read-only]
error
: const
QMediaRecorder::Error
返迴當前錯誤狀態。
訪問函數:
| QMediaRecorder::Error | error () const |
通知程序信號:
| void | errorChanged () |
另請參閱 errorString ().
[read-only]
errorString
: const
QString
返迴描述當前錯誤狀態的字符串。
訪問函數:
| QString | errorString () const |
通知程序信號:
| void | errorChanged () |
另請參閱 error ().
Returns the recording media format.
訪問函數:
| QMediaFormat | mediaFormat () const |
| void | setMediaFormat (const QMediaFormat & format ) |
通知程序信號:
| void | mediaFormatChanged () |
Returns the metaData associated with the recording.
訪問函數:
| QMediaMetaData | metaData () const |
| void | setMetaData (const QMediaMetaData & metaData ) |
通知程序信號:
| void | metaDataChanged () |
此特性保持媒體內容的目的地位置。
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.
訪問函數:
| QUrl | outputLocation () const |
| void | setOutputLocation (const QUrl & location ) |
Returns the recording quality.
訪問函數:
| QMediaRecorder::Quality | quality () const |
| void | setQuality (QMediaRecorder::Quality quality ) |
[read-only]
recorderState
: const
QMediaRecorder::RecorderState
此特性保持媒體錄製器的當前狀態。
The state property represents the user request and is changed synchronously during record (), pause () 或 stop () calls. Recorder state may also change asynchronously when recording fails.
訪問函數:
| QMediaRecorder::RecorderState | recorderState () const |
通知程序信號:
| 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 .
[虛擬]
QMediaRecorder::
~QMediaRecorder
()
銷毀媒體錄製器對象。
[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.
注意: 通知程序信號對於特性 actualLocation .
添加 metaData to the recorded media.
Returns the bit rate of the compressed audio stream in bits per second.
另請參閱 setAudioBitRate ().
[signal]
void
QMediaRecorder::
audioBitRateChanged
()
Signals when the recording audio bit rate changes.
Returns the number of audio channels.
另請參閱 setAudioChannelCount ().
[signal]
void
QMediaRecorder::
audioChannelCountChanged
()
Signals when the recording audio channel count changes.
Returns the audio sample rate in Hz.
另請參閱 setAudioSampleRate ().
[signal]
void
QMediaRecorder::
audioSampleRateChanged
()
Signals when the recording audio sample rate changes.
Returns the media capture session.
[signal]
void
QMediaRecorder::
durationChanged
(
qint64
duration
)
發射信號,當 duration of the recorded media has changed.
注意: 通知程序信號對於特性 duration .
[signal]
void
QMediaRecorder::
encoderSettingsChanged
()
Signals when the encoder settings change.
Returns the encoding mode.
另請參閱 setEncodingMode () 和 EncodingMode .
[signal]
void
QMediaRecorder::
encodingModeChanged
()
Signals when the encoding mode changes.
[signal]
void
QMediaRecorder::
errorOccurred
(
QMediaRecorder::Error
error
, const
QString
&
errorString
)
發射信號,當 error has occurred, with errorString containing a description of the error.
返迴
true
if media recorder service ready to use.
[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.
注意: 通知程序信號對於特性 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.
[signal]
void
QMediaRecorder::
qualityChanged
()
Signals when the recording quality changes.
[slot]
void
QMediaRecorder::
record
()
開始錄製。
While the recorder state is changed immediately to c{ QMediaRecorder::RecordingState }, recording may start asynchronously.
若錄製失敗
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.
Returns the current media recorder state.
注意: Getter function for property recorderState.
另請參閱 QMediaRecorder::RecorderState .
[signal]
void
QMediaRecorder::
recorderStateChanged
(
QMediaRecorder::RecorderState
state
)
Signals that a media recorder's state 已改變。
注意: 通知程序信號對於特性 recorderState .
設置音頻 bitRate 以位每秒為單位。
另請參閱 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.
另請參閱 audioChannelCount ().
設置音頻 sampleRate (以 Hz 為單位)。
值
-1
indicates the recorder should make an optimal choice based on what is available from the audio source, and the limitations of the codec.
另請參閱 audioSampleRate ().
Sets the encoding mode 設置。
若 ConstantQualityEncoding is set, the quality encoding parameter is used and bit rates are ignored, otherwise the bitrates are used.
另請參閱 encodingMode () 和 EncodingMode .
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 函數對於特性 metaData .
另請參閱 metaData ().
設置視頻 bitRate 以位每秒為單位。
另請參閱 videoBitRate ().
設置視頻 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.
另請參閱 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.
另請參閱 videoResolution ().
設置 width and height of the resolution of the encoded video.
這是重載函數。
[slot]
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 .
Returns the bit rate of the compressed video stream in bits per second.
另請參閱 setVideoBitRate ().
[signal]
void
QMediaRecorder::
videoBitRateChanged
()
Signals when the recording video bit rate changes.
返迴視頻幀速率。
另請參閱 setVideoFrameRate ().
[signal]
void
QMediaRecorder::
videoFrameRateChanged
()
Signals when the recording video frame rate changes.
Returns the resolution of the encoded video.
另請參閱 setVideoResolution ().
[signal]
void
QMediaRecorder::
videoResolutionChanged
()
Signals when the video recording resolution changes.