FFmpeg
ass_split.h
Go to the documentation of this file.
1 /*
2  * SSA/ASS spliting functions
3  * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_ASS_SPLIT_H
23 #define AVCODEC_ASS_SPLIT_H
24 
25 /**
26  * fields extracted from the [Script Info] section
27  */
28 typedef struct {
29  char *script_type; /**< SSA script format version (eg. v4.00) */
30  char *collisions; /**< how subtitles are moved to prevent collisions */
31  int play_res_x; /**< video width that ASS coords are referring to */
32  int play_res_y; /**< video height that ASS coords are referring to */
33  float timer; /**< time multiplier to apply to SSA clock (in %) */
35 
36 /**
37  * fields extracted from the [V4(+) Styles] section
38  */
39 typedef struct {
40  char *name; /**< name of the tyle (case sensitive) */
41  char *font_name; /**< font face (case sensitive) */
42  int font_size; /**< font height */
43  int primary_color; /**< color that a subtitle will normally appear in */
45  int outline_color; /**< color for outline in ASS, called tertiary in SSA */
46  int back_color; /**< color of the subtitle outline or shadow */
47  int bold; /**< whether text is bold (1) or not (0) */
48  int italic; /**< whether text is italic (1) or not (0) */
49  int underline; /**< whether text is underlined (1) or not (0) */
50  int strikeout;
51  float scalex;
52  float scaley;
53  float spacing;
54  float angle;
56  float outline;
57  float shadow;
58  int alignment; /**< position of the text (left, center, top...),
59  defined after the layout of the numpad
60  (1-3 sub, 4-6 mid, 7-9 top) */
61  int margin_l;
62  int margin_r;
63  int margin_v;
65  int encoding;
66 } ASSStyle;
67 
68 /**
69  * fields extracted from the [Events] section
70  */
71 typedef struct {
72  int readorder;
73  int layer; /**< higher numbered layers are drawn over lower numbered */
74  int start; /**< start time of the dialog in centiseconds */
75  int end; /**< end time of the dialog in centiseconds */
76  char *style; /**< name of the ASSStyle to use with this dialog */
77  char *name;
78  int margin_l;
79  int margin_r;
80  int margin_v;
81  char *effect;
82  char *text; /**< actual text which will be displayed as a subtitle,
83  can include style override control codes (see
84  ff_ass_split_override_codes()) */
85 } ASSDialog;
86 
87 /**
88  * structure containing the whole split ASS data
89  */
90 typedef struct {
91  ASSScriptInfo script_info; /**< general information about the SSA script*/
92  ASSStyle *styles; /**< array of split out styles */
93  int styles_count; /**< number of ASSStyle in the styles array */
94  ASSDialog *dialogs; /**< array of split out dialogs */
95  int dialogs_count; /**< number of ASSDialog in the dialogs array*/
96 } ASS;
97 
98 /**
99  * This struct can be casted to ASS to access to the split data.
100  */
101 typedef struct ASSSplitContext ASSSplitContext;
102 
103 /**
104  * Split a full ASS file or a ASS header from a string buffer and store
105  * the split structure in a newly allocated context.
106  *
107  * @param buf String containing the ASS formatted data.
108  * @return Newly allocated struct containing split data.
109  */
110 ASSSplitContext *ff_ass_split(const char *buf);
111 
112 /**
113  * Split one or several ASS "Dialogue" lines from a string buffer and store
114  * them in an already initialized context.
115  *
116  * @param ctx Context previously initialized by ff_ass_split().
117  * @param buf String containing the ASS "Dialogue" lines.
118  * @param cache Set to 1 to keep all the previously split ASSDialog in
119  * the context, or set to 0 to free all the previously split
120  * ASSDialog.
121  * @param number If not NULL, the pointed integer will be set to the number
122  * of split ASSDialog.
123  * @return Pointer to the first split ASSDialog.
124  */
126  int cache, int *number);
127 
128 /**
129  * Free a dialogue obtained from ff_ass_split_dialog2().
130  */
131 void ff_ass_free_dialog(ASSDialog **dialogp);
132 
133 /**
134  * Split one ASS Dialogue line from a string buffer.
135  *
136  * @param ctx Context previously initialized by ff_ass_split().
137  * @param buf String containing the ASS "Dialogue" line.
138  * @return Pointer to the split ASSDialog. Must be freed with ff_ass_free_dialog()
139  */
141 
142 /**
143  * Free all the memory allocated for an ASSSplitContext.
144  *
145  * @param ctx Context previously initialized by ff_ass_split().
146  */
148 
149 
150 /**
151  * Set of callback functions corresponding to each override codes that can
152  * be encountered in a "Dialogue" Text field.
153  */
154 typedef struct {
155  /**
156  * @defgroup ass_styles ASS styles
157  * @{
158  */
159  void (*text)(void *priv, const char *text, int len);
160  void (*new_line)(void *priv, int forced);
161  void (*style)(void *priv, char style, int close);
162  void (*color)(void *priv, unsigned int /* color */, unsigned int color_id);
163  void (*alpha)(void *priv, int alpha, int alpha_id);
164  void (*font_name)(void *priv, const char *name);
165  void (*font_size)(void *priv, int size);
166  void (*alignment)(void *priv, int alignment);
167  void (*cancel_overrides)(void *priv, const char *style);
168  /** @} */
169 
170  /**
171  * @defgroup ass_functions ASS functions
172  * @{
173  */
174  void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
175  void (*origin)(void *priv, int x, int y);
176  /** @} */
177 
178  /**
179  * @defgroup ass_end end of Dialogue Event
180  * @{
181  */
182  void (*end)(void *priv);
183  /** @} */
185 
186 /**
187  * Split override codes out of a ASS "Dialogue" Text field.
188  *
189  * @param callbacks Set of callback functions called for each override code
190  * encountered.
191  * @param priv Opaque pointer passed to the callback functions.
192  * @param buf The ASS "Dialogue" Text field to split.
193  * @return >= 0 on success otherwise an error code <0
194  */
196  const char *buf);
197 
198 /**
199  * Find an ASSStyle structure by its name.
200  *
201  * @param ctx Context previously initialized by ff_ass_split().
202  * @param style name of the style to search for.
203  * @return the ASSStyle corresponding to style, or NULL if style can't be found
204  */
205 ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style);
206 
207 #endif /* AVCODEC_ASS_SPLIT_H */
ASSScriptInfo::timer
float timer
time multiplier to apply to SSA clock (in %)
Definition: ass_split.h:33
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
ASSCodesCallbacks
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
Definition: ass_split.h:154
color
Definition: vf_paletteuse.c:582
ASSDialog::end
int end
end time of the dialog in centiseconds
Definition: ass_split.h:75
ASSStyle::margin_r
int margin_r
Definition: ass_split.h:62
ASSStyle::alignment
int alignment
position of the text (left, center, top...), defined after the layout of the numpad (1-3 sub,...
Definition: ass_split.h:58
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
callbacks
static const OMX_CALLBACKTYPE callbacks
Definition: omx.c:332
ASS::styles
ASSStyle * styles
array of split out styles
Definition: ass_split.h:92
ASSCodesCallbacks::style
void(* style)(void *priv, char style, int close)
Definition: ass_split.h:161
ASSStyle::font_size
int font_size
font height
Definition: ass_split.h:42
t1
#define t1
Definition: regdef.h:29
ff_ass_style_get
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
Definition: ass_split.c:589
ASSDialog::style
char * style
name of the ASSStyle to use with this dialog
Definition: ass_split.h:76
ASSStyle::angle
float angle
Definition: ass_split.h:54
ASSStyle::font_name
char * font_name
font face (case sensitive)
Definition: ass_split.h:41
ff_ass_split_free
void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
Definition: ass_split.c:481
ASSDialog::margin_r
int margin_r
Definition: ass_split.h:79
ASS::dialogs
ASSDialog * dialogs
array of split out dialogs
Definition: ass_split.h:94
ASSDialog::effect
char * effect
Definition: ass_split.h:81
ASSDialog::start
int start
start time of the dialog in centiseconds
Definition: ass_split.h:74
ff_ass_split_dialog
ASSDialog * ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, int cache, int *number)
Split one or several ASS "Dialogue" lines from a string buffer and store them in an already initializ...
Definition: ass_split.c:413
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ASSScriptInfo::play_res_y
int play_res_y
video height that ASS coords are referring to
Definition: ass_split.h:32
ff_ass_split_override_codes
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
Definition: ass_split.c:494
ASS
structure containing the whole split ASS data
Definition: ass_split.h:90
ASSDialog::name
char * name
Definition: ass_split.h:77
ASSDialog::margin_l
int margin_l
Definition: ass_split.h:78
ASSScriptInfo::play_res_x
int play_res_x
video width that ASS coords are referring to
Definition: ass_split.h:31
ASSStyle::margin_l
int margin_l
Definition: ass_split.h:61
ff_ass_split
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...
Definition: ass_split.c:374
ASSStyle::primary_color
int primary_color
color that a subtitle will normally appear in
Definition: ass_split.h:43
ASSCodesCallbacks::alpha
void(* alpha)(void *priv, int alpha, int alpha_id)
Definition: ass_split.h:163
ASSStyle::spacing
float spacing
Definition: ass_split.h:53
ASSScriptInfo
fields extracted from the [Script Info] section
Definition: ass_split.h:28
ASSScriptInfo::script_type
char * script_type
SSA script format version (eg.
Definition: ass_split.h:29
ASSSplitContext
This struct can be casted to ASS to access to the split data.
Definition: ass_split.c:197
ASSStyle
fields extracted from the [V4(+) Styles] section
Definition: ass_split.h:39
ff_ass_split_dialog2
ASSDialog * ff_ass_split_dialog2(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
Definition: ass_split.c:444
ASSStyle::scaley
float scaley
Definition: ass_split.h:52
ASSStyle::underline
int underline
whether text is underlined (1) or not (0)
Definition: ass_split.h:49
ASSDialog::text
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
Definition: ass_split.h:82
ASSStyle::name
char * name
name of the tyle (case sensitive)
Definition: ass_split.h:40
size
int size
Definition: twinvq_data.h:11134
ASSStyle::strikeout
int strikeout
Definition: ass_split.h:50
ASSStyle::italic
int italic
whether text is italic (1) or not (0)
Definition: ass_split.h:48
ASSScriptInfo::collisions
char * collisions
how subtitles are moved to prevent collisions
Definition: ass_split.h:30
ASSStyle::secondary_color
int secondary_color
Definition: ass_split.h:44
ff_ass_free_dialog
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog2().
Definition: ass_split.c:432
ASSStyle::encoding
int encoding
Definition: ass_split.h:65
ASSStyle::back_color
int back_color
color of the subtitle outline or shadow
Definition: ass_split.h:46
ASSStyle::alpha_level
int alpha_level
Definition: ass_split.h:64
ASSDialog::margin_v
int margin_v
Definition: ass_split.h:80
ASSStyle::outline
float outline
Definition: ass_split.h:56
ASS::styles_count
int styles_count
number of ASSStyle in the styles array
Definition: ass_split.h:93
len
int len
Definition: vorbis_enc_data.h:452
ASS::dialogs_count
int dialogs_count
number of ASSDialog in the dialogs array
Definition: ass_split.h:95
ASSStyle::margin_v
int margin_v
Definition: ass_split.h:63
ASSStyle::scalex
float scalex
Definition: ass_split.h:51
t2
#define t2
Definition: regdef.h:30
ASSStyle::border_style
int border_style
Definition: ass_split.h:55
ASSStyle::outline_color
int outline_color
color for outline in ASS, called tertiary in SSA
Definition: ass_split.h:45
ASSDialog
fields extracted from the [Events] section
Definition: ass_split.h:71
ASSDialog::readorder
int readorder
Definition: ass_split.h:72
ASSStyle::shadow
float shadow
Definition: ass_split.h:57
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
ASSCodesCallbacks::alignment
void(* alignment)(void *priv, int alignment)
Definition: ass_split.h:166
ASSDialog::layer
int layer
higher numbered layers are drawn over lower numbered
Definition: ass_split.h:73
ASSStyle::bold
int bold
whether text is bold (1) or not (0)
Definition: ass_split.h:47
ASSCodesCallbacks::text
void(* text)(void *priv, const char *text, int len)
Definition: ass_split.h:159
ASS::script_info
ASSScriptInfo script_info
general information about the SSA script
Definition: ass_split.h:91