QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QtVideoRecorder Class Reference

#include <QtVideoRecorder.h>

Inheritance diagram for QtVideoRecorder:
Collaboration diagram for QtVideoRecorder:

Signals

void recordingChanged (bool recording)
void recordingStarted (const QString &file)
void recordingFinished (const QString &file, const QString &error)
 error is empty for a recording that finished normally.

Public Member Functions

 QtVideoRecorder (QObject *parent=nullptr)
 ~QtVideoRecorder () override
QMediaRecorder * mediaRecorder () const
bool recording () const
 From the first encoded frame until the recorder stops.
bool active () const
 Recording, or waiting for the first frame to encode.
void start (const QString &file, QMediaFormat::FileFormat container, QMediaFormat::VideoCodec codec=QMediaFormat::VideoCodec::Unspecified, QMediaRecorder::Quality quality=QMediaRecorder::HighQuality)
void stop ()
void stopAndWait (std::chrono::milliseconds timeout=kFinishTimeout)

Static Public Member Functions

static QList< QMediaFormat > recordingFormats (QMediaFormat::FileFormat container, QMediaFormat::VideoCodec codec=QMediaFormat::VideoCodec::Unspecified)
static QStringList recordingCodecs ()
static QMediaFormat::VideoCodec recordingCodec (const QString &key)
 The codec of key key, as recordingCodecs() names it; Unspecified for an empty or unknown key.
static QString recordingCodecName (const QString &key)
 The name of the codec of key key, such as "H.264", for display.
static QMediaFormat::FileFormat container (VideoReceiver::FileFormat format)
 The container of format.
static QMediaRecorder::Quality recordingQuality (int value)
 The quality of value value, one of VideoSettings::uvcRecordingQuality's; HighQuality for any other.

Static Public Attributes

static constexpr std::chrono::seconds kFinishTimeout {5}
 How long an owner going away waits for a recording's file to be finished.

Friends

class QtVideoRecorderTest

Detailed Description

Records the video of a QMediaCaptureSession with Qt Multimedia's encoders: a USB camera's (UVCCameraController), or a stream's decoded frames fed in through a QVideoFrameInput (QtMultimediaVideoReceiver). The capture session records with mediaRecorder(), which outlives it: a session going away mid-recording makes it finish the file and report it.

start() records to "<file without suffix>.<suffix of the format used>", at the quality asked for, trying recordingFormats() in turn until one encodes. recordingStarted() follows once the first frame is encoded, or recordingFinished() with an error; a failed attempt leaves no file behind. Recordings carry their start time and VideoReceiver::recordingComment().

Definition at line 22 of file QtVideoRecorder.h.

Constructor & Destructor Documentation

◆ QtVideoRecorder()

QtVideoRecorder::QtVideoRecorder ( QObject * parent = nullptr)
explicit

Definition at line 64 of file QtVideoRecorder.cc.

References recordingChanged(), and recordingStarted().

◆ ~QtVideoRecorder()

QtVideoRecorder::~QtVideoRecorder ( )
overridedefault

Member Function Documentation

◆ active()

bool QtVideoRecorder::active ( ) const
inline

Recording, or waiting for the first frame to encode.

Definition at line 41 of file QtVideoRecorder.h.

◆ container()

QMediaFormat::FileFormat QtVideoRecorder::container ( VideoReceiver::FileFormat format)
static

◆ mediaRecorder()

QMediaRecorder * QtVideoRecorder::mediaRecorder ( ) const
inline

Definition at line 35 of file QtVideoRecorder.h.

◆ recording()

bool QtVideoRecorder::recording ( ) const
inline

From the first encoded frame until the recorder stops.

Definition at line 38 of file QtVideoRecorder.h.

Referenced by recordingChanged(), and stopAndWait().

◆ recordingChanged

void QtVideoRecorder::recordingChanged ( bool recording)
signal

◆ recordingCodec()

QMediaFormat::VideoCodec QtVideoRecorder::recordingCodec ( const QString & key)
static

The codec of key key, as recordingCodecs() names it; Unspecified for an empty or unknown key.

Definition at line 143 of file QtVideoRecorder.cc.

Referenced by recordingCodecName().

◆ recordingCodecName()

QString QtVideoRecorder::recordingCodecName ( const QString & key)
static

The name of the codec of key key, such as "H.264", for display.

Definition at line 150 of file QtVideoRecorder.cc.

References recordingCodec().

Referenced by UVCCameraController::recordingCodecName().

◆ recordingCodecs()

QStringList QtVideoRecorder::recordingCodecs ( )
static

The codecs Qt can encode a recording in here, in any of the recording containers, as the keys of QMediaFormat::VideoCodec (such as "H264"): the values of VideoSettings::uvcRecordingCodec. recordingFormats()'s fallbacks come first, in its order.

Definition at line 120 of file QtVideoRecorder.cc.

References container().

Referenced by UVCCameraController::recordingCodecs().

◆ recordingFinished

void QtVideoRecorder::recordingFinished ( const QString & file,
const QString & error )
signal

error is empty for a recording that finished normally.

Referenced by QtMultimediaVideoReceiver::QtMultimediaVideoReceiver(), start(), and UVCCameraController::UVCCameraController().

◆ recordingFormats()

QList< QMediaFormat > QtVideoRecorder::recordingFormats ( QMediaFormat::FileFormat container,
QMediaFormat::VideoCodec codec = QMediaFormat::VideoCodec::Unspecified )
static

The formats start() tries for container, best first: codec where Qt can encode it, then H.264 and the other codecs Qt can encode here, down to software MPEG-2. In container where Qt can write it, else in another container. Qt counts a hardware encoder as encodable even where the hardware turns it down, hence the fallbacks.

Definition at line 83 of file QtVideoRecorder.cc.

References container().

Referenced by start().

◆ recordingQuality()

QMediaRecorder::Quality QtVideoRecorder::recordingQuality ( int value)
static

The quality of value value, one of VideoSettings::uvcRecordingQuality's; HighQuality for any other.

Definition at line 168 of file QtVideoRecorder.cc.

◆ recordingStarted

void QtVideoRecorder::recordingStarted ( const QString & file)
signal

◆ start()

void QtVideoRecorder::start ( const QString & file,
QMediaFormat::FileFormat container,
QMediaFormat::VideoCodec codec = QMediaFormat::VideoCodec::Unspecified,
QMediaRecorder::Quality quality = QMediaRecorder::HighQuality )

Records the capture session mediaRecorder() is set on to file, in container and codec where Qt can encode them: see recordingFormats(). quality sets how large the file gets: Qt encodes for a constant quality, or for a bit rate it works out from one where the encoder takes only that (Android, iOS, Intel Macs). Reports recordingFinished() with an error when no format encodes.

Definition at line 174 of file QtVideoRecorder.cc.

References container(), recordingFinished(), and recordingFormats().

◆ stop()

void QtVideoRecorder::stop ( )

Definition at line 219 of file QtVideoRecorder.cc.

Referenced by stopAndWait().

◆ stopAndWait()

void QtVideoRecorder::stopAndWait ( std::chrono::milliseconds timeout = kFinishTimeout)

Stops recording and waits up to timeout for the file to be finished: Qt writes it on its own thread, which the application's exit would cut short.

Definition at line 225 of file QtVideoRecorder.cc.

References recording(), recordingChanged(), and stop().

◆ QtVideoRecorderTest

friend class QtVideoRecorderTest
friend

Definition at line 26 of file QtVideoRecorder.h.

References QtVideoRecorderTest.

Referenced by QtVideoRecorderTest.

Member Data Documentation

◆ kFinishTimeout

std::chrono::seconds QtVideoRecorder::kFinishTimeout {5}
staticconstexpr

How long an owner going away waits for a recording's file to be finished.

Definition at line 30 of file QtVideoRecorder.h.


The documentation for this class was generated from the following files: