30#define WEBVTT_STACK_SIZE 64
58 s->stack[
s->stack_ptr++] =
c;
64 if (
s->stack_ptr <= 0)
66 return s->stack[--
s->stack_ptr];
72 for (
i =
s->stack_ptr-1;
i >= 0;
i--)
80 webvtt_print(
s,
"</%c>",
tag);
89 while (
s->stack_ptr !=
i)
100 webvtt_print(
s,
"<b>");
104 webvtt_print(
s,
"<i>");
108 webvtt_print(
s,
"<u>");
123 webvtt_print(
s,
"<%02"PRId64
":%02"PRId64
":%02"PRId64
".%03"PRId64
">", hour,
min, sec, millisec);
125 webvtt_print(
s,
"<%02"PRId64
":%02"PRId64
".%03"PRId64
">",
min, sec, millisec);
131 if (
s->pending_duration_ms <= 0)
134 int64_t next_ts =
s->current_time_ms <= INT64_MAX -
s->pending_duration_ms ?
135 s->current_time_ms +
s->pending_duration_ms : INT64_MAX;
136 if (next_ts >
s->cue_start_ms && next_ts < s->cue_end_ms &&
137 next_ts >
s->last_timestamp_ms) {
139 s->last_timestamp_ms = next_ts;
141 s->current_time_ms = next_ts;
142 s->pending_duration_ms = 0;
154 webvtt_print(
s,
"\n");
172 webvtt_print(priv,
"<%c>", style);
203 unsigned char *buf,
int bufsize,
const AVSubtitle *sub)
217 s->cue_start_ms =
s->cue_end_ms = 0;
219 s->current_time_ms =
s->cue_start_ms;
220 s->last_timestamp_ms = -1;
221 s->pending_duration_ms = 0;
247 return s->buffer.len;
const FFCodec ff_webvtt_encoder
#define ASS_DEFAULT_UNDERLINE
#define ASS_DEFAULT_ITALIC
av_cold ASSSplitContext * ff_ass_split(const char *buf)
Split a full ASS file or a ASS header from a string buffer and store the split structure in a newly a...
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog().
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
av_cold void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
ASSDialog * ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_ENCODE_SUB_CB(func)
#define CODEC_LONG_NAME(str)
int(* init)(AVBSFContext *ctx)
@ SUBTITLE_ASS
Formatted text, the ass field must be set by the decoder and is authoritative.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
static void webvtt_karaoke_cb(void *priv, unsigned int duration)
static void webvtt_new_line_cb(void *priv, int forced)
static int webvtt_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
static av_cold int webvtt_encode_init(AVCodecContext *avctx)
static void webvtt_flush_karaoke_timestamp(WebVTTContext *s)
static av_cold int webvtt_encode_close(AVCodecContext *avctx)
static char webvtt_stack_pop(WebVTTContext *s)
#define WEBVTT_STACK_SIZE
static void webvtt_print_timestamp(WebVTTContext *s, int64_t millisec)
static int webvtt_stack_find(WebVTTContext *s, const char c)
static void webvtt_style_cb(void *priv, char style, int close)
static void webvtt_end_cb(void *priv)
static void webvtt_close_tag(WebVTTContext *s, char tag)
static void webvtt_text_cb(void *priv, const char *text, int len)
static void webvtt_style_apply(WebVTTContext *s, const char *style)
static void webvtt_cancel_overrides_cb(void *priv, const char *style)
static int webvtt_stack_push(WebVTTContext *s, const char c)
static const ASSCodesCallbacks webvtt_callbacks
static void webvtt_stack_push_pop(WebVTTContext *s, const char c, int close)
#define av_printf_format(fmtpos, attrpos)
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
fields extracted from the [Events] section
char * style
name of the ASSStyle to use with this dialog
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
This struct can be casted to ASS to access to the split data.
fields extracted from the [V4(+) Styles] section
int italic
whether text is italic (1) or not (0)
int bold
whether text is bold (1) or not (0)
int underline
whether text is underlined (1) or not (0)
main external API structure.
uint8_t * subtitle_header
Rational number (pair of numerator and denominator).
char * ass
0 terminated ASS/SSA compatible event line.
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
int64_t last_timestamp_ms
char stack[WEBVTT_STACK_SIZE]
ASSSplitContext * ass_ctx
int64_t pending_duration_ms