QAudioBufferInput 類

QAudioBufferInput 類用於提供自定義音頻緩衝為 QMediaRecorder 透過 QMediaCaptureSession . 更多...

頭: #include <QAudioBufferInput>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
Since: Qt 6.8
繼承: QObject

公共函數

QAudioBufferInput (QObject * parent = nullptr)
QAudioBufferInput (const QAudioFormat & format , QObject * parent = nullptr)
virtual ~QAudioBufferInput () override
QMediaCaptureSession * captureSession () const
QAudioFormat format () const
bool sendAudioBuffer (const QAudioBuffer & audioBuffer )

信號

void readyToSendAudioBuffer ()

詳細描述

QAudioBufferInput 僅支持采用 FFmpeg 後端。

Custom audio buffers can be recorded by connecting a QAudioBufferInput QMediaRecorder QMediaCaptureSession . For a pull mode implementation, call sendAudioBuffer () in response to the readyToSendAudioBuffer () signal. In the snippet below this is done by connecting the signal to a slot in a custom media generator class. The slot function emits another signal with a new audio buffer, which is connected to sendAudioBuffer ():

QMediaCaptureSession session;
QMediaRecorder recorder;
QAudioBufferInput audioInput;
session.setRecorder(&recorder);
session.setAudioBufferInput(&audioInput);
MediaGenerator generator; // Custom class providing audio buffers
connect(&audioInput, &QAudioBufferInput::readyToSendAudioBuffer,
        &generator, &MediaGenerator::nextAudioBuffer);
connect(&generator, &MediaGenerator::audioBufferReady,
        &audioInput, &QAudioBufferInput::sendAudioBuffer);
recorder.record();
					

Here's a minimal implementation of the slot function that provides audio buffers:

void MediaGenerator::nextAudioBuffer()
{
    QAudioBuffer buffer = nextBuffer();
    emit audioBufferReady(buffer);
}
					

更多細節見 readyToSendAudioBuffer () 和 sendAudioBuffer ().

另請參閱 QMediaRecorder and QMediaCaptureSession .

成員函數文檔編製

[explicit] QAudioBufferInput:: QAudioBufferInput ( QObject * parent = nullptr)

構造新的 QAudioBufferInput 對象采用 parent .

[explicit] QAudioBufferInput:: QAudioBufferInput (const QAudioFormat & format , QObject * parent = nullptr)

構造新的 QAudioBufferInput 對象采用音頻 format and parent .

指定 format will work as a hint for the initialization of the matching audio encoder upon invoking QMediaRecorder::record (). If the format is not specified or not valid, the audio encoder will be initialized upon sending the first audio buffer.

We recommend specifying the format if you know in advance what kind of audio buffers you're going to send.

[override virtual noexcept] QAudioBufferInput:: ~QAudioBufferInput ()

銷毀對象。

QMediaCaptureSession *QAudioBufferInput:: captureSession () const

Returns the capture session this audio buffer input is connected to, or a nullptr if the audio buffer input is not connected to a capture session.

使用 QMediaCaptureSession::setAudioBufferInput () to connect the audio buffer input to a session.

QAudioFormat QAudioBufferInput:: format () const

Returns the audio format that was specified upon construction of the audio buffer input.

[signal] void QAudioBufferInput:: readyToSendAudioBuffer ()

Signals that a new audio buffer can be sent to the audio buffer input. After receiving the signal, if you have audio date to be sent, invoke sendAudioBuffer once or in a loop until it returns false .

另請參閱 sendAudioBuffer ().

bool QAudioBufferInput:: sendAudioBuffer (const QAudioBuffer & audioBuffer )

發送 QAudioBuffer to QMediaRecorder 透過 QMediaCaptureSession .

返迴 true if the specified audioBuffer has been sent successfully to the destination. Returns false , if the buffer hasn't been sent, which can happen if the instance is not assigned to QMediaCaptureSession , the session doesn't have a media recorder, the media recorder is not started or its queue is full. The readyToSendAudioBuffer () signal will be emitted as soon as the destination is able to handle a new audio buffer.

Sending of an empty audio buffer is treated by QMediaRecorder as an end of the input stream. QMediaRecorder stops the recording automatically if QMediaRecorder::autoStop is true and all the inputs have reported the end of the stream.