22#include "config_components.h"
32#define SRT_STACK_SIZE 64
56 s->stack[
s->stack_ptr++] =
c;
62 if (
s->stack_ptr <= 0)
64 return s->stack[--
s->stack_ptr];
70 for (
i =
s->stack_ptr-1;
i >= 0;
i--)
78 srt_print(
s,
"</%c%s>",
tag,
tag ==
'f' ?
"ont" :
"");
87 while (
s->stack_ptr !=
i)
101 srt_print(
s,
"<font");
107 srt_print(
s,
" color=\"#%06x\"",
108 (
c & 0xFF0000) >> 16 |
c & 0xFF00 | (
c & 0xFF) << 16);
126 s->alignment_applied = 1;
148 srt_print(priv,
"\n");
155 srt_print(priv,
"<%c>", style);
163 if (
color != 0xFFFFFFFF)
164 srt_print(priv,
"<font color=\"#%06x\">",
172 srt_print(priv,
"<font face=\"%s\">",
name);
179 srt_print(priv,
"<font size=\"%d\">",
size);
185 if (!
s->alignment_applied && alignment >= 0) {
186 srt_print(
s,
"{\\an%d}", alignment);
187 s->alignment_applied = 1;
197static void srt_move_cb(
void *priv,
int x1,
int y1,
int x2,
int y2,
228 unsigned char *buf,
int bufsize,
const AVSubtitle *sub,
248 s->alignment_applied = 0;
263 return s->buffer.len;
267 unsigned char *buf,
int bufsize,
const AVSubtitle *sub)
273 unsigned char *buf,
int bufsize,
const AVSubtitle *sub)
285#if CONFIG_SRT_ENCODER
299#if CONFIG_SUBRIP_ENCODER
312#if CONFIG_TEXT_ENCODER
const FFCodec ff_text_encoder
const FFCodec ff_subrip_encoder
const FFCodec ff_srt_encoder
static av_cold void close(AVCodecParserContext *s)
#define ASS_DEFAULT_ALIGNMENT
#define ASS_DEFAULT_FONT_SIZE
#define ASS_DEFAULT_COLOR
#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.
@ AV_CODEC_ID_TEXT
raw UTF-8 text
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.
static void srt_alignment_cb(void *priv, int alignment)
static av_cold int srt_encode_close(AVCodecContext *avctx)
static int text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
static void srt_cancel_overrides_cb(void *priv, const char *style)
static void srt_close_tag(SRTContext *s, char tag)
static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2, int t1, int t2)
static void srt_color_cb(void *priv, unsigned int color, unsigned int color_id)
static void srt_style_apply(SRTContext *s, const char *style)
static int srt_stack_find(SRTContext *s, const char c)
static void srt_font_name_cb(void *priv, const char *name)
static const ASSCodesCallbacks srt_callbacks
static void srt_new_line_cb(void *priv, int forced)
static int srt_stack_push(SRTContext *s, const char c)
static void srt_text_cb(void *priv, const char *text, int len)
static char srt_stack_pop(SRTContext *s)
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub, const ASSCodesCallbacks *cb)
static int srt_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
static const ASSCodesCallbacks text_callbacks
static void srt_font_size_cb(void *priv, int size)
static void srt_style_cb(void *priv, char style, int close)
static av_cold int srt_encode_init(AVCodecContext *avctx)
static void srt_stack_push_pop(SRTContext *s, const char c, int close)
static void srt_end_cb(void *priv)
#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 primary_color
color that a subtitle will normally appear in
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)
char * font_name
font face (case sensitive)
int alignment
position of the text (left, center, top...), defined after the layout of the numpad (1-3 sub,...
main external API structure.
uint8_t * subtitle_header
char * ass
0 terminated ASS/SSA compatible event line.
char stack[SRT_STACK_SIZE]
ASSSplitContext * ass_ctx
static double cb(void *priv, double x, double y)