annotate ffmpeg/libavcodec/ass_split.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * SSA/ASS spliting functions
yading@10 3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 #ifndef AVCODEC_ASS_SPLIT_H
yading@10 23 #define AVCODEC_ASS_SPLIT_H
yading@10 24
yading@10 25 /**
yading@10 26 * fields extracted from the [Script Info] section
yading@10 27 */
yading@10 28 typedef struct {
yading@10 29 char *script_type; /**< SSA script format version (eg. v4.00) */
yading@10 30 char *collisions; /**< how subtitles are moved to prevent collisions */
yading@10 31 int play_res_x; /**< video width that ASS coords are referring to */
yading@10 32 int play_res_y; /**< video height that ASS coords are referring to */
yading@10 33 float timer; /**< time multiplier to apply to SSA clock (in %) */
yading@10 34 } ASSScriptInfo;
yading@10 35
yading@10 36 /**
yading@10 37 * fields extracted from the [V4(+) Styles] section
yading@10 38 */
yading@10 39 typedef struct {
yading@10 40 char *name; /**< name of the tyle (case sensitive) */
yading@10 41 char *font_name; /**< font face (case sensitive) */
yading@10 42 int font_size; /**< font height */
yading@10 43 int primary_color; /**< color that a subtitle will normally appear in */
yading@10 44 int back_color; /**< color of the subtitle outline or shadow */
yading@10 45 int bold; /**< whether text is bold (1) or not (0) */
yading@10 46 int italic; /**< whether text is italic (1) or not (0) */
yading@10 47 int underline; /**< whether text is underlined (1) or not (0) */
yading@10 48 int alignment; /**< position of the text (left, center, top...),
yading@10 49 defined after the layout of the numpad
yading@10 50 (1-3 sub, 4-6 mid, 7-9 top) */
yading@10 51 } ASSStyle;
yading@10 52
yading@10 53 /**
yading@10 54 * fields extracted from the [Events] section
yading@10 55 */
yading@10 56 typedef struct {
yading@10 57 int layer; /**< higher numbered layers are drawn over lower numbered */
yading@10 58 int start; /**< start time of the dialog in centiseconds */
yading@10 59 int end; /**< end time of the dialog in centiseconds */
yading@10 60 char *style; /**< name of the ASSStyle to use with this dialog */
yading@10 61 char *text; /**< actual text which will be displayed as a subtitle,
yading@10 62 can include style override control codes (see
yading@10 63 ff_ass_split_override_codes()) */
yading@10 64 } ASSDialog;
yading@10 65
yading@10 66 /**
yading@10 67 * structure containing the whole split ASS data
yading@10 68 */
yading@10 69 typedef struct {
yading@10 70 ASSScriptInfo script_info; /**< general information about the SSA script*/
yading@10 71 ASSStyle *styles; /**< array of split out styles */
yading@10 72 int styles_count; /**< number of ASSStyle in the styles array */
yading@10 73 ASSDialog *dialogs; /**< array of split out dialogs */
yading@10 74 int dialogs_count; /**< number of ASSDialog in the dialogs array*/
yading@10 75 } ASS;
yading@10 76
yading@10 77 /**
yading@10 78 * This struct can be casted to ASS to access to the split data.
yading@10 79 */
yading@10 80 typedef struct ASSSplitContext ASSSplitContext;
yading@10 81
yading@10 82 /**
yading@10 83 * Split a full ASS file or a ASS header from a string buffer and store
yading@10 84 * the split structure in a newly allocated context.
yading@10 85 *
yading@10 86 * @param buf String containing the ASS formated data.
yading@10 87 * @return Newly allocated struct containing split data.
yading@10 88 */
yading@10 89 ASSSplitContext *ff_ass_split(const char *buf);
yading@10 90
yading@10 91 /**
yading@10 92 * Split one or several ASS "Dialogue" lines from a string buffer and store
yading@10 93 * them in a already initialized context.
yading@10 94 *
yading@10 95 * @param ctx Context previously initialized by ff_ass_split().
yading@10 96 * @param buf String containing the ASS "Dialogue" lines.
yading@10 97 * @param cache Set to 1 to keep all the previously split ASSDialog in
yading@10 98 * the context, or set to 0 to free all the previously split
yading@10 99 * ASSDialog.
yading@10 100 * @param number If not NULL, the pointed integer will be set to the number
yading@10 101 * of split ASSDialog.
yading@10 102 * @return Pointer to the first split ASSDialog.
yading@10 103 */
yading@10 104 ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf,
yading@10 105 int cache, int *number);
yading@10 106
yading@10 107 /**
yading@10 108 * Free all the memory allocated for an ASSSplitContext.
yading@10 109 *
yading@10 110 * @param ctx Context previously initialized by ff_ass_split().
yading@10 111 */
yading@10 112 void ff_ass_split_free(ASSSplitContext *ctx);
yading@10 113
yading@10 114
yading@10 115 /**
yading@10 116 * Set of callback functions corresponding to each override codes that can
yading@10 117 * be encountered in a "Dialogue" Text field.
yading@10 118 */
yading@10 119 typedef struct {
yading@10 120 /**
yading@10 121 * @defgroup ass_styles ASS styles
yading@10 122 * @{
yading@10 123 */
yading@10 124 void (*text)(void *priv, const char *text, int len);
yading@10 125 void (*new_line)(void *priv, int forced);
yading@10 126 void (*style)(void *priv, char style, int close);
yading@10 127 void (*color)(void *priv, unsigned int /* color */, unsigned int color_id);
yading@10 128 void (*alpha)(void *priv, int alpha, int alpha_id);
yading@10 129 void (*font_name)(void *priv, const char *name);
yading@10 130 void (*font_size)(void *priv, int size);
yading@10 131 void (*alignment)(void *priv, int alignment);
yading@10 132 void (*cancel_overrides)(void *priv, const char *style);
yading@10 133 /** @} */
yading@10 134
yading@10 135 /**
yading@10 136 * @defgroup ass_functions ASS functions
yading@10 137 * @{
yading@10 138 */
yading@10 139 void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
yading@10 140 void (*origin)(void *priv, int x, int y);
yading@10 141 /** @} */
yading@10 142
yading@10 143 /**
yading@10 144 * @defgroup ass_end end of Dialogue Event
yading@10 145 * @{
yading@10 146 */
yading@10 147 void (*end)(void *priv);
yading@10 148 /** @} */
yading@10 149 } ASSCodesCallbacks;
yading@10 150
yading@10 151 /**
yading@10 152 * Split override codes out of a ASS "Dialogue" Text field.
yading@10 153 *
yading@10 154 * @param callbacks Set of callback functions called for each override code
yading@10 155 * encountered.
yading@10 156 * @param priv Opaque pointer passed to the callback functions.
yading@10 157 * @param buf The ASS "Dialogue" Text field to split.
yading@10 158 * @return >= 0 on success otherwise an error code <0
yading@10 159 */
yading@10 160 int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
yading@10 161 const char *buf);
yading@10 162
yading@10 163 /**
yading@10 164 * Find an ASSStyle structure by its name.
yading@10 165 *
yading@10 166 * @param ctx Context previously initialized by ff_ass_split().
yading@10 167 * @param style name of the style to search for.
yading@10 168 * @return the ASSStyle corresponding to style, or NULL if style can't be found
yading@10 169 */
yading@10 170 ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style);
yading@10 171
yading@10 172 #endif /* AVCODEC_ASS_SPLIT_H */