yading@10: /* yading@10: * SSA/ASS spliting functions yading@10: * Copyright (c) 2010 Aurelien Jacobs yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #ifndef AVCODEC_ASS_SPLIT_H yading@10: #define AVCODEC_ASS_SPLIT_H yading@10: yading@10: /** yading@10: * fields extracted from the [Script Info] section yading@10: */ yading@10: typedef struct { yading@10: char *script_type; /**< SSA script format version (eg. v4.00) */ yading@10: char *collisions; /**< how subtitles are moved to prevent collisions */ yading@10: int play_res_x; /**< video width that ASS coords are referring to */ yading@10: int play_res_y; /**< video height that ASS coords are referring to */ yading@10: float timer; /**< time multiplier to apply to SSA clock (in %) */ yading@10: } ASSScriptInfo; yading@10: yading@10: /** yading@10: * fields extracted from the [V4(+) Styles] section yading@10: */ yading@10: typedef struct { yading@10: char *name; /**< name of the tyle (case sensitive) */ yading@10: char *font_name; /**< font face (case sensitive) */ yading@10: int font_size; /**< font height */ yading@10: int primary_color; /**< color that a subtitle will normally appear in */ yading@10: int back_color; /**< color of the subtitle outline or shadow */ yading@10: int bold; /**< whether text is bold (1) or not (0) */ yading@10: int italic; /**< whether text is italic (1) or not (0) */ yading@10: int underline; /**< whether text is underlined (1) or not (0) */ yading@10: int alignment; /**< position of the text (left, center, top...), yading@10: defined after the layout of the numpad yading@10: (1-3 sub, 4-6 mid, 7-9 top) */ yading@10: } ASSStyle; yading@10: yading@10: /** yading@10: * fields extracted from the [Events] section yading@10: */ yading@10: typedef struct { yading@10: int layer; /**< higher numbered layers are drawn over lower numbered */ yading@10: int start; /**< start time of the dialog in centiseconds */ yading@10: int end; /**< end time of the dialog in centiseconds */ yading@10: char *style; /**< name of the ASSStyle to use with this dialog */ yading@10: char *text; /**< actual text which will be displayed as a subtitle, yading@10: can include style override control codes (see yading@10: ff_ass_split_override_codes()) */ yading@10: } ASSDialog; yading@10: yading@10: /** yading@10: * structure containing the whole split ASS data yading@10: */ yading@10: typedef struct { yading@10: ASSScriptInfo script_info; /**< general information about the SSA script*/ yading@10: ASSStyle *styles; /**< array of split out styles */ yading@10: int styles_count; /**< number of ASSStyle in the styles array */ yading@10: ASSDialog *dialogs; /**< array of split out dialogs */ yading@10: int dialogs_count; /**< number of ASSDialog in the dialogs array*/ yading@10: } ASS; yading@10: yading@10: /** yading@10: * This struct can be casted to ASS to access to the split data. yading@10: */ yading@10: typedef struct ASSSplitContext ASSSplitContext; yading@10: yading@10: /** yading@10: * Split a full ASS file or a ASS header from a string buffer and store yading@10: * the split structure in a newly allocated context. yading@10: * yading@10: * @param buf String containing the ASS formated data. yading@10: * @return Newly allocated struct containing split data. yading@10: */ yading@10: ASSSplitContext *ff_ass_split(const char *buf); yading@10: yading@10: /** yading@10: * Split one or several ASS "Dialogue" lines from a string buffer and store yading@10: * them in a already initialized context. yading@10: * yading@10: * @param ctx Context previously initialized by ff_ass_split(). yading@10: * @param buf String containing the ASS "Dialogue" lines. yading@10: * @param cache Set to 1 to keep all the previously split ASSDialog in yading@10: * the context, or set to 0 to free all the previously split yading@10: * ASSDialog. yading@10: * @param number If not NULL, the pointed integer will be set to the number yading@10: * of split ASSDialog. yading@10: * @return Pointer to the first split ASSDialog. yading@10: */ yading@10: ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, yading@10: int cache, int *number); yading@10: yading@10: /** yading@10: * Free all the memory allocated for an ASSSplitContext. yading@10: * yading@10: * @param ctx Context previously initialized by ff_ass_split(). yading@10: */ yading@10: void ff_ass_split_free(ASSSplitContext *ctx); yading@10: yading@10: yading@10: /** yading@10: * Set of callback functions corresponding to each override codes that can yading@10: * be encountered in a "Dialogue" Text field. yading@10: */ yading@10: typedef struct { yading@10: /** yading@10: * @defgroup ass_styles ASS styles yading@10: * @{ yading@10: */ yading@10: void (*text)(void *priv, const char *text, int len); yading@10: void (*new_line)(void *priv, int forced); yading@10: void (*style)(void *priv, char style, int close); yading@10: void (*color)(void *priv, unsigned int /* color */, unsigned int color_id); yading@10: void (*alpha)(void *priv, int alpha, int alpha_id); yading@10: void (*font_name)(void *priv, const char *name); yading@10: void (*font_size)(void *priv, int size); yading@10: void (*alignment)(void *priv, int alignment); yading@10: void (*cancel_overrides)(void *priv, const char *style); yading@10: /** @} */ yading@10: yading@10: /** yading@10: * @defgroup ass_functions ASS functions yading@10: * @{ yading@10: */ yading@10: void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2); yading@10: void (*origin)(void *priv, int x, int y); yading@10: /** @} */ yading@10: yading@10: /** yading@10: * @defgroup ass_end end of Dialogue Event yading@10: * @{ yading@10: */ yading@10: void (*end)(void *priv); yading@10: /** @} */ yading@10: } ASSCodesCallbacks; yading@10: yading@10: /** yading@10: * Split override codes out of a ASS "Dialogue" Text field. yading@10: * yading@10: * @param callbacks Set of callback functions called for each override code yading@10: * encountered. yading@10: * @param priv Opaque pointer passed to the callback functions. yading@10: * @param buf The ASS "Dialogue" Text field to split. yading@10: * @return >= 0 on success otherwise an error code <0 yading@10: */ yading@10: int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, yading@10: const char *buf); yading@10: yading@10: /** yading@10: * Find an ASSStyle structure by its name. yading@10: * yading@10: * @param ctx Context previously initialized by ff_ass_split(). yading@10: * @param style name of the style to search for. yading@10: * @return the ASSStyle corresponding to style, or NULL if style can't be found yading@10: */ yading@10: ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style); yading@10: yading@10: #endif /* AVCODEC_ASS_SPLIT_H */