QMediaRecorder 类用于编码和录制捕获会话。 更多...
头: | #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 () |
QMediaRecorder 类编码和录制的媒体生成于 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
|
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. |
常量 | 值 | 描述 |
---|---|---|
QMediaRecorder::NoError
|
0
|
没有错误。 |
QMediaRecorder::ResourceError
|
1
|
设备未就绪 (或不可用)。 |
QMediaRecorder::FormatError
|
2
|
不支持当前格式。 |
QMediaRecorder::OutOfSpaceError
|
3
|
设备没有剩余空间。 |
QMediaRecorder::LocationNotWritable
|
4
|
输出位置不可写。 |
枚举品质编码级别。
常量 | 值 |
---|---|
QMediaRecorder::VeryLowQuality
|
0
|
QMediaRecorder::LowQuality
|
1
|
QMediaRecorder::NormalQuality
|
2
|
QMediaRecorder::HighQuality
|
3
|
QMediaRecorder::VeryHighQuality
|
4
|
常量 | 值 | 描述 |
---|---|---|
QMediaRecorder::StoppedState
|
0
|
录制器不活动。 |
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 ().
返回录制媒体格式。
访问函数:
QMediaFormat | mediaFormat () const |
void | setMediaFormat (const QMediaFormat & format ) |
通知程序信号:
void | mediaFormatChanged () |
返回录制关联的 metaData。
访问函数:
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 ) |
返回录制品质。
访问函数:
QMediaRecorder::Quality | quality () const |
void | setQuality (QMediaRecorder::Quality quality ) |
通知程序信号:
void | qualityChanged () |
[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 .
[virtual noexcept]
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 到录制媒体。
Returns the bit rate of the compressed audio stream in bits per second.
注意: getter 函数对于特性 audioBitRate。
另请参阅 setAudioBitRate ().
[signal]
void
QMediaRecorder::
audioBitRateChanged
()
Signals when the recording audio bit rate changes.
注意: 通知程序信号对于特性 audioBitRate .
Returns the number of audio channels.
注意: Getter function for property audioChannelCount.
另请参阅 setAudioChannelCount ().
[signal]
void
QMediaRecorder::
audioChannelCountChanged
()
Signals when the recording audio channel count changes.
注意: 通知程序信号对于特性 audioChannelCount .
Returns the audio sample rate in Hz.
注意: Getter function for property audioSampleRate.
另请参阅 setAudioSampleRate ().
[signal]
void
QMediaRecorder::
audioSampleRateChanged
()
Signals when the recording audio sample rate changes.
注意: 通知程序信号对于特性 audioSampleRate .
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.
注意: Getter function for property encodingMode.
另请参阅 setEncodingMode () 和 EncodingMode .
[signal]
void
QMediaRecorder::
encodingModeChanged
()
Signals when the encoding mode changes.
注意: 通知程序信号对于特性 encodingMode .
[signal]
void
QMediaRecorder::
errorOccurred
(
QMediaRecorder::Error
error
, const
QString
&
errorString
)
Signals that an 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
()
暂停录制。
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.
注意: 通知程序信号对于特性 quality .
[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 函数对于特性 recorderState。
另请参阅 QMediaRecorder::RecorderState .
[signal]
void
QMediaRecorder::
recorderStateChanged
(
QMediaRecorder::RecorderState
state
)
Signals that a media recorder's state 已改变。
注意: 通知程序信号对于特性 recorderState .
设置音频 bitRate 以位每秒为单位。
注意: setter 函数对于特性 audioBitRate .
另请参阅 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.
注意: setter 函数对于特性 audioChannelCount .
另请参阅 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.
注意: setter 函数对于特性 audioSampleRate .
另请参阅 audioSampleRate ().
设置编码 mode 设置。
若 ConstantQualityEncoding is set, the quality encoding parameter is used and bit rates are ignored, otherwise the bitrates are used.
注意: setter 函数对于特性 encodingMode .
另请参阅 encodingMode () 和 EncodingMode .
将元数据设为 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 以位每秒为单位。
注意: setter 函数对于特性 videoBitRate .
另请参阅 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.
注意: setter 函数对于特性 videoFrameRate .
另请参阅 videoFrameRate ().
Sets the resolution of the encoded video to size .
传递空 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 函数对于特性 videoResolution .
另请参阅 videoResolution ().
设置 width and height of the resolution of the encoded video.
这是重载函数。
注意: setter 函数对于特性 videoResolution .
[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.
注意: getter 函数对于特性 videoBitRate。
另请参阅 setVideoBitRate ().
[signal]
void
QMediaRecorder::
videoBitRateChanged
()
Signals when the recording video bit rate changes.
注意: 通知程序信号对于特性 videoBitRate .
返回视频帧速率。
注意: getter 函数对于特性 videoFrameRate。
另请参阅 setVideoFrameRate ().
[signal]
void
QMediaRecorder::
videoFrameRateChanged
()
Signals when the recording video frame rate changes.
注意: 通知程序信号对于特性 videoFrameRate .
Returns the resolution of the encoded video.
注意: getter 函数对于特性 videoResolution。
另请参阅 setVideoResolution ().
[signal]
void
QMediaRecorder::
videoResolutionChanged
()
Signals when the video recording resolution changes.
注意: 通知程序信号对于特性 videoResolution .