avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::SubtitleFrame Class Reference

Owning, move-only subtitle frame. More...

#include <subtitle.h>

Public Member Functions

 SubtitleFrame (SubtitleFrame &&other) noexcept
 Move the frame.
SubtitleFrame & operator= (SubtitleFrame &&other) noexcept
 Move assignment: frees the current content and takes the other frame's.
 SubtitleFrame (const SubtitleFrame &)=delete
SubtitleFrame & operator= (const SubtitleFrame &)=delete
SubtitleFrame clone (OptionalErrorCode ec=throws()) const
 Deep copy: strings, bitmap (linesize(0) * height) and palette are copied.
AVSubtitle * raw () noexcept
 The underlying FFmpeg subtitle.
const AVSubtitle * raw () const noexcept
 The underlying FFmpeg subtitle, read-only.
bool isValid () const noexcept
 True when the frame contains rectangles or is a decoded empty subtitle (for example, a bitmap subtitle that clears the screen).
 operator bool () const noexcept
 Whether the frame holds a subtitle.
uint16_t format () const noexcept
 0 for graphics, non-zero for text.
void setFormat (uint16_t format) noexcept
 Set the subtitle kind.
bool isText () const noexcept
 Whether the subtitle is textual.
uint32_t startDisplayTime () const noexcept
 Start of the display interval, relative to pts().
uint32_t endDisplayTime () const noexcept
 End of the display interval, relative to pts().
void setStartDisplayTime (uint32_t ms) noexcept
 Set the start of the display interval.
void setEndDisplayTime (uint32_t ms) noexcept
 Set the end of the display interval.
Timestamp pts () const noexcept
 Presentation timestamp of the subtitle.
void setPts (const Timestamp &ts)
 Set the presentation timestamp.
const Rational & timeBase () const noexcept
 Time base of pts().
void setTimeBase (const Rational &value) noexcept
 Set the time base, rescaling the stored timestamp.
Timestamp startTime () const noexcept
 pts + startDisplayTime(), in the frame time base.
Timestamp endTime () const noexcept
 pts + endDisplayTime(), in the frame time base.
int streamIndex () const noexcept
 Index of the stream the subtitle came from.
void setStreamIndex (int index) noexcept
 Set the stream index.
bool isComplete () const noexcept
 True when a decoder produced this frame, including empty subtitles.
void setComplete (bool complete) noexcept
 Mark the frame as produced by a decoder.
size_t numRects () const noexcept
 Number of rectangles in the frame.
SubtitleRect rect (size_t index) const
 Rectangle by index.
std::vector< SubtitleRect > rects () const
 All rectangles as a vector of views.
SubtitleRect addRect (AVSubtitleType type=SUBTITLE_NONE, OptionalErrorCode ec=throws())
 Appends a new empty rectangle owned by this frame.
void clear () noexcept
 Releases all rectangles and resets the frame state.
std::string_view text () const noexcept
 Text of the subtitle: the payload of the first text rectangle.
std::string_view ass () const noexcept
 ASS line of the subtitle: the payload of the first ASS rectangle.

Static Public Member Functions

static SubtitleFrame fromAss (std::string_view ass, OptionalErrorCode ec=throws())
 Build a frame from one ASS dialogue line.
static SubtitleFrame fromText (std::string_view text, OptionalErrorCode ec=throws())
 Build a frame from plain text.

Detailed Description

Wraps AVSubtitle. AVSubtitle has no reference counting API in FFmpeg, so copies are disabled; use clone() for an explicit deep copy.

The pts value is interpreted in AV_TIME_BASE units, as required by FFmpeg. The default time base is 1/AV_TIME_BASE; setTimeBase() rescales the stored pts value.

Constructor & Destructor Documentation

◆ SubtitleFrame()

av::SubtitleFrame::SubtitleFrame ( SubtitleFrame && other)
noexcept
Parameters
otherthe frame to move from; left empty

Member Function Documentation

◆ addRect()

SubtitleRect av::SubtitleFrame::addRect ( AVSubtitleType type = SUBTITLE_NONE,
OptionalErrorCode ec = throws() )
Parameters
type
ec
Returns
a view of the new rectangle

◆ ass()

std::string_view av::SubtitleFrame::ass ( ) const
noexcept
Returns
the line, empty when the frame has none

◆ clear()

void av::SubtitleFrame::clear ( )
noexcept

Free all rectangles and reset the frame state.

◆ clone()

SubtitleFrame av::SubtitleFrame::clone ( OptionalErrorCode ec = throws()) const

Planes 2 and 3 are ignored because FFmpeg subtitle codecs do not use them.

Parameters
ec
Returns
an independent copy of the frame

◆ endDisplayTime()

uint32_t av::SubtitleFrame::endDisplayTime ( ) const
noexcept
Returns
milliseconds from pts() until the subtitle disappears

◆ endTime()

Timestamp av::SubtitleFrame::endTime ( ) const
noexcept
Returns
the absolute end of the display interval

◆ format()

uint16_t av::SubtitleFrame::format ( ) const
noexcept
Returns
zero for bitmap subtitles, non-zero for text

◆ fromAss()

SubtitleFrame av::SubtitleFrame::fromAss ( std::string_view ass,
OptionalErrorCode ec = throws() )
static

The result contains a single SUBTITLE_ASS rectangle with a zero start display time, which is what text subtitle encoders accept.

Parameters
assthe dialogue line, without the "Dialogue:" prefix
echolder for the error code
Returns
the new frame, or an invalid one on failure
Examples
api2-generate-subtitles.cpp.

◆ fromText()

SubtitleFrame av::SubtitleFrame::fromText ( std::string_view text,
OptionalErrorCode ec = throws() )
static

The result contains a single SUBTITLE_TEXT rectangle with a zero start display time.

Parameters
textthe text of the subtitle
echolder for the error code
Returns
the new frame, or an invalid one on failure

◆ isComplete()

bool av::SubtitleFrame::isComplete ( ) const
noexcept
Returns
the completeness flag

◆ isText()

bool av::SubtitleFrame::isText ( ) const
noexcept
Returns
true when format() is non-zero

◆ isValid()

bool av::SubtitleFrame::isValid ( ) const
noexcept
Returns
true when the frame is usable

◆ numRects()

size_t av::SubtitleFrame::numRects ( ) const
noexcept
Returns
the rectangle count

◆ operator bool()

av::SubtitleFrame::operator bool ( ) const
noexcept
Returns
true when the frame is valid, including empty subtitles that clear the screen

◆ operator=()

SubtitleFrame & av::SubtitleFrame::operator= ( SubtitleFrame && other)
noexcept
Parameters
otherthe frame to move from; left empty
Returns
this frame

◆ pts()

Timestamp av::SubtitleFrame::pts ( ) const
noexcept
Returns
the timestamp in timeBase() units
Examples
api2-subtitles.cpp.

◆ raw() [1/2]

const AVSubtitle * av::SubtitleFrame::raw ( ) const
noexcept
Returns
the raw structure, never null

◆ raw() [2/2]

AVSubtitle * av::SubtitleFrame::raw ( )
noexcept
Returns
the raw structure, never null
Note
Borrowed. Do not free it; the frame owns it.

◆ rect()

SubtitleRect av::SubtitleFrame::rect ( size_t index) const
Parameters
indexzero-based index; must be less than numRects()
Returns
a non-owning view of the rectangle

◆ rects()

std::vector< SubtitleRect > av::SubtitleFrame::rects ( ) const
Returns
the views; they share the frame's lifetime

◆ setComplete()

void av::SubtitleFrame::setComplete ( bool complete)
noexcept
Parameters
completetrue for a decoded subtitle, including an empty one

◆ setEndDisplayTime()

void av::SubtitleFrame::setEndDisplayTime ( uint32_t ms)
noexcept
Parameters
msmilliseconds from pts() until the subtitle disappears

◆ setFormat()

void av::SubtitleFrame::setFormat ( uint16_t format)
noexcept
Parameters
formatzero for bitmap subtitles, non-zero for text

◆ setPts()

void av::SubtitleFrame::setPts ( const Timestamp & ts)
Parameters
tsthe timestamp; its time base replaces the stored one

◆ setStartDisplayTime()

void av::SubtitleFrame::setStartDisplayTime ( uint32_t ms)
noexcept
Parameters
msmilliseconds from pts() until the subtitle appears

◆ setStreamIndex()

void av::SubtitleFrame::setStreamIndex ( int index)
noexcept
Parameters
indexindex of the subtitle stream in the container

◆ setTimeBase()

void av::SubtitleFrame::setTimeBase ( const Rational & value)
noexcept
Parameters
valuetimestamp units per second

◆ startDisplayTime()

uint32_t av::SubtitleFrame::startDisplayTime ( ) const
noexcept
Returns
milliseconds from pts() until the subtitle appears

◆ startTime()

Timestamp av::SubtitleFrame::startTime ( ) const
noexcept
Returns
the absolute start of the display interval

◆ streamIndex()

int av::SubtitleFrame::streamIndex ( ) const
noexcept
Returns
the stream index, or -1 when it has not been set

◆ text()

std::string_view av::SubtitleFrame::text ( ) const
noexcept
Returns
the text, empty when the frame has none

◆ timeBase()

const Rational & av::SubtitleFrame::timeBase ( ) const
noexcept
Returns
the time base; it defaults to 1/AV_TIME_BASE

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