19#if AVCPP_CXX_STANDARD >= 20
24#include <libavcodec/avcodec.h>
53 SubtitleRect() =
default;
74 operator
bool() const noexcept;
82 AVSubtitleType
type() const noexcept;
95 int x() const noexcept;
101 int y() const noexcept;
193 uint8_t *
data(
size_t plane = 0) noexcept;
201 const uint8_t *
data(
size_t plane = 0) const noexcept;
230#if AVCPP_CXX_STANDARD >= 20
235 std::span<const uint8_t>
bitmap() const noexcept;
276 SubtitleFrame()
noexcept;
290 SubtitleFrame &
operator=(SubtitleFrame &&other)
noexcept;
291 SubtitleFrame(
const SubtitleFrame &) =
delete;
292 SubtitleFrame &
operator=(
const SubtitleFrame &) =
delete;
310 AVSubtitle *
raw() noexcept;
316 const AVSubtitle *
raw() const noexcept;
330 operator
bool() const noexcept;
512 void swap(SubtitleFrame &other) noexcept;
515 Rational m_timeBase{1, AV_TIME_BASE};
516 int m_streamIndex{-1};
517 bool m_isComplete{
false};
FFmpeg version and API compatibility switches.
Error codes, error categories and the OptionalErrorCode convention.
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
Rational number: a numerator and a denominator.
Definition rational.h:49
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.
bool isComplete() const noexcept
True when a decoder produced this frame, including empty subtitles.
const Rational & timeBase() const noexcept
Time base of pts().
void setPts(const Timestamp &ts)
Set the presentation timestamp.
bool isText() const noexcept
Whether the subtitle is textual.
std::string_view text() const noexcept
Text of the subtitle: the payload of the first text rectangle.
uint32_t endDisplayTime() const noexcept
End of the display interval, relative to pts().
SubtitleRect rect(size_t index) const
Rectangle by index.
Timestamp endTime() const noexcept
pts + endDisplayTime(), in the frame time base.
void setEndDisplayTime(uint32_t ms) noexcept
Set the end of the display interval.
std::vector< SubtitleRect > rects() const
All rectangles as a vector of views.
void setComplete(bool complete) noexcept
Mark the frame as produced by a decoder.
SubtitleFrame clone(OptionalErrorCode ec=throws()) const
Deep copy: strings, bitmap (linesize(0) * height) and palette are copied.
static SubtitleFrame fromText(std::string_view text, OptionalErrorCode ec=throws())
Build a frame from plain text.
void clear() noexcept
Releases all rectangles and resets the frame state.
size_t numRects() const noexcept
Number of rectangles in the frame.
bool isValid() const noexcept
True when the frame contains rectangles or is a decoded empty subtitle (for example,...
SubtitleFrame(SubtitleFrame &&other) noexcept
Move the frame.
static SubtitleFrame fromAss(std::string_view ass, OptionalErrorCode ec=throws())
Build a frame from one ASS dialogue line.
std::string_view ass() const noexcept
ASS line of the subtitle: the payload of the first ASS rectangle.
SubtitleRect addRect(AVSubtitleType type=SUBTITLE_NONE, OptionalErrorCode ec=throws())
Appends a new empty rectangle owned by this frame.
void setStartDisplayTime(uint32_t ms) noexcept
Set the start of the display interval.
void setStreamIndex(int index) noexcept
Set the stream index.
int streamIndex() const noexcept
Index of the stream the subtitle came from.
uint32_t startDisplayTime() const noexcept
Start of the display interval, relative to pts().
Timestamp pts() const noexcept
Presentation timestamp of the subtitle.
AVSubtitle * raw() noexcept
The underlying FFmpeg subtitle.
void setFormat(uint16_t format) noexcept
Set the subtitle kind.
SubtitleFrame & operator=(SubtitleFrame &&other) noexcept
Move assignment: frees the current content and takes the other frame's.
uint16_t format() const noexcept
0 for graphics, non-zero for text.
Non-owning view over AVSubtitleRect.
Definition subtitle.h:51
int y() const noexcept
Vertical position of the rectangle.
int width() const noexcept
Width of the bitmap.
void setArea(int x, int y, int width, int height) noexcept
Set the position and the size at once.
int nbColors() const noexcept
Number of palette entries of a bitmap rectangle.
std::span< const uint8_t > bitmap() const noexcept
Plane 0 as an index bitmap: linesize(0) * height() bytes.
std::span< const uint32_t > palette() const noexcept
Plane 1 as a palette: nbColors() entries.
std::string_view ass() const noexcept
ASS/SSA event line.
void setForced(bool forced) noexcept
Mark the rectangle as forced.
void setBitmap(const uint8_t *data, int stride, int width, int height, OptionalErrorCode ec=throws())
Sets plane 0 to an index bitmap and updates width, height and linesize.
int x() const noexcept
Horizontal position of the rectangle.
std::string_view text() const noexcept
Plain UTF-8 text.
void setAss(std::string_view ass, OptionalErrorCode ec=throws())
Store an ASS/SSA event line in the rectangle.
SubtitleRect(AVSubtitleRect *rect)
Wrap a rectangle.
void setText(std::string_view text, OptionalErrorCode ec=throws())
Store plain UTF-8 text in the rectangle.
void clearText() noexcept
Free the text payload and clear the pointer.
AVSubtitleType type() const noexcept
Kind of payload the rectangle carries.
void clearAss() noexcept
Free the ASS payload and clear the pointer.
void setPalette(const uint32_t *palette, int count, OptionalErrorCode ec=throws())
Sets plane 1 to a palette and updates nb_colors.
bool isValid() const noexcept
Whether the view refers to a rectangle.
int height() const noexcept
Height of the bitmap.
void setType(AVSubtitleType type) noexcept
Set the payload kind.
bool isForced() const noexcept
Whether the rectangle is flagged as forced.
uint8_t * data(size_t plane=0) noexcept
Pointer to one image plane.
int linesize(size_t plane=0) const noexcept
Distance between two rows of a plane.
The Timestamp class represents timestamp value and it timebase.
Definition timestamp.h:25
FFmpeg types re-exported for the public API and small value wrappers.
Root namespace of the library.
Definition audioresampler.h:19
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition averror.h:310
Rational numbers, time bases and arithmetic on them.
std::string_view defaultAssHeader() noexcept
Returns a built-in ASS/SSA script header accepted by the FFmpeg text subtitle encoders (subrip,...
Frame timestamps and their arithmetic.