Class QfSubtitleWriter
Collects timed text and writes it out as a SubRip (.srt) subtitle file. More...
#include <qfsubtitlewriter.h>
Inherits the following classes: QObject
Public Properties
| Type | Name |
|---|---|
| property int | minimumCueDuration |
Public Signals
| Type | Name |
|---|---|
| signal void | minimumCueDurationChanged |
Public Functions
| Type | Name |
|---|---|
| QfSubtitleWriter (QObject * parent=nullptr) |
|
| Q_INVOKABLE void | addCue (qint64 elapsedTime, const QString & text) |
| Q_INVOKABLE void | clear () Drops every cue, returning the writer to its initial state. |
| int | minimumCueDuration () const Returns the shortest duration in milliseconds an individual cue may have. |
| void | setMinimumCueDuration (int duration) Sets the shortest duration in milliseconds an individual cue may have. |
| Q_INVOKABLE bool | write (const QString & mediaFilePath, qint64 endTime) |
Public Static Functions
| Type | Name |
|---|---|
| QString | formatTimestamp (qint64 milliseconds) Returns milliseconds as a SubRip timestamp, HH:MM:SS,zzz. |
| QString | sanitizeCueText (const QString & text) Returns text with line endings normalized and blank lines removed, as a blank line would end the cue. |
| QString | subtitleFilePath (const QString & mediaFilePath) Returns mediaFilePath with its suffix replaced by .srt. |
Detailed Description
The writer holds a single open cue and closes it only when the text changes, so a caller can feed it every update without filtering out repetitions. Changes arriving faster than minimumCueDuration() are folded into the open cue instead of producing subtitles too short to read.
The caller owns the clock: it passes the elapsed time of every cue and the final duration to write(), which keeps the cue timeline expressed against the media itself.
Public Properties Documentation
property minimumCueDuration [1/2]
int QfSubtitleWriter::minimumCueDuration;
Public Signals Documentation
signal minimumCueDurationChanged
void QfSubtitleWriter::minimumCueDurationChanged;
Public Functions Documentation
function QfSubtitleWriter
explicit QfSubtitleWriter::QfSubtitleWriter (
QObject * parent=nullptr
)
function addCue
Q_INVOKABLE void QfSubtitleWriter::addCue (
qint64 elapsedTime,
const QString & text
)
Records text as being valid from elapsedTime milliseconds onwards.
Passing the text the open cue already holds does nothing, which is what stops an unchanging value from producing a stream of identical cues. An empty text closes the open cue without starting a new one, leaving a gap in the track.
function clear
Drops every cue, returning the writer to its initial state.
Q_INVOKABLE void QfSubtitleWriter::clear ()
function minimumCueDuration [2/2]
Returns the shortest duration in milliseconds an individual cue may have.
inline int QfSubtitleWriter::minimumCueDuration () const
function setMinimumCueDuration
Sets the shortest duration in milliseconds an individual cue may have.
void QfSubtitleWriter::setMinimumCueDuration (
int duration
)
function write
Q_INVOKABLE bool QfSubtitleWriter::write (
const QString & mediaFilePath,
qint64 endTime
)
Writes the cues as a SubRip file next to mediaFilePath, closing the open cue at endTime milliseconds. Returns FALSE and writes no file when there is nothing to write.
Public Static Functions Documentation
function formatTimestamp
Returns milliseconds as a SubRip timestamp, HH:MM:SS,zzz.
static QString QfSubtitleWriter::formatTimestamp (
qint64 milliseconds
)
function sanitizeCueText
Returns text with line endings normalized and blank lines removed, as a blank line would end the cue.
static QString QfSubtitleWriter::sanitizeCueText (
const QString & text
)
function subtitleFilePath
Returns mediaFilePath with its suffix replaced by .srt.
static QString QfSubtitleWriter::subtitleFilePath (
const QString & mediaFilePath
)
The documentation for this class was generated from the following file src/core/qfsubtitlewriter.h