The QVideoFrameInput class is used for providing custom video frames to QMediaRecorder or a video output through QMediaCaptureSession . 更多...
| 头: |
#include <QVideoFrameInput>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
|
| qmake: |
QT += multimedia
|
| Since: | Qt 6.8 |
| 继承: | QObject |
| QVideoFrameInput (QObject * parent = nullptr) | |
| QVideoFrameInput (const QVideoFrameFormat & format , QObject * parent = nullptr) | |
| virtual | ~QVideoFrameInput () override |
| QMediaCaptureSession * | captureSession () const |
| QVideoFrameFormat | format () const |
| bool | sendVideoFrame (const QVideoFrame & frame ) |
| void | readyToSendVideoFrame () |
QVideoFrameInput is only supported with the FFmpeg backend.
Custom video frames can be recorded by connecting a QVideoFrameInput 和 QMediaRecorder 到 QMediaCaptureSession . For a pull mode implementation, call sendVideoFrame () in response to the readyToSendVideoFrame () 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 video frame, which is connected to sendVideoFrame ():
QMediaCaptureSession session; QMediaRecorder recorder; QVideoFrameInput videoInput; session.setRecorder(&recorder); session.setVideoFrameInput(&videoInput); MediaGenerator generator; // Custom class providing video frames connect(&videoInput, &QVideoFrameInput::readyToSendVideoFrame, &generator, &MediaGenerator::nextVideoFrame); connect(&generator, &MediaGenerator::videoFrameReady, &videoInput, &QVideoFrameInput::sendVideoFrame); recorder.record();
Here's a minimal implementation of the slot function that provides video frames:
void MediaGenerator::nextVideoFrame() { QVideoFrame frame = nextFrame(); emit videoFrameReady(frame); }
更多细节见 readyToSendVideoFrame () 和 sendVideoFrame ().
另请参阅 QMediaRecorder , QMediaCaptureSession ,和 QVideoSink .
[explicit]
QVideoFrameInput::
QVideoFrameInput
(
QObject
*
parent
= nullptr)
Constructs a new QVideoFrameInput object with parent .
[explicit]
QVideoFrameInput::
QVideoFrameInput
(const
QVideoFrameFormat
&
format
,
QObject
*
parent
= nullptr)
Constructs a new QVideoFrameInput object with video frame format and parent .
指定 format will work as a hint for the initialization of the matching video encoder upon invoking QMediaRecorder::record (). If the format is not specified or not valid, the video encoder will be initialized upon sending the first frame. Sending of video frames with another pixel format and size after initialization of the matching video encoder might cause a performance penalty during recording.
We recommend specifying the format if you know in advance what kind of frames you're going to send.
[override virtual noexcept]
QVideoFrameInput::
~QVideoFrameInput
()
销毁对象。
Returns the capture session this video frame input is connected to, or a
nullptr
if the video frame input is not connected to a capture session.
使用 QMediaCaptureSession::setVideoFrameInput () to connect the video frame input to a session.
Returns the video frame format that was specified upon construction of the video frame input.
[signal]
void
QVideoFrameInput::
readyToSendVideoFrame
()
Signals that a new frame can be sent to the video frame input. After receiving the signal, if you have frames to be sent, invoke
sendVideoFrame
once or in a loop until it returns
false
.
另请参阅 sendVideoFrame ().
发送 QVideoFrame to QMediaRecorder or a video output through QMediaCaptureSession .
返回
true
if the specified
frame
has been sent successfully to the destination. Returns
false
, if the frame hasn't been sent, which can happen if the instance is not assigned to
QMediaCaptureSession
, the session doesn't have video outputs or a media recorder, the media recorder is not started or its queue is full. The signal
readyToSendVideoFrame
will be sent as soon as the destination is able to handle a new frame.
Sending of an empty video frame 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.