You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.8KB

  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. #ifndef AVCODEC_ASS_SPLIT_H
  22. #define AVCODEC_ASS_SPLIT_H
  23. /**
  24. * fields extracted from the [Script Info] section
  25. */
  26. typedef struct {
  27. char *script_type; /**< SSA script format version (eg. v4.00) */
  28. char *collisions; /**< how subtitles are moved to prevent collisions */
  29. int play_res_x; /**< video width that ASS coords are referring to */
  30. int play_res_y; /**< video height that ASS coords are referring to */
  31. float timer; /**< time multiplier to apply to SSA clock (in %) */
  32. } ASSScriptInfo;
  33. /**
  34. * fields extracted from the [V4(+) Styles] section
  35. */
  36. typedef struct {
  37. char *name; /**< name of the tyle (case sensitive) */
  38. char *font_name; /**< font face (case sensitive) */
  39. int font_size; /**< font height */
  40. int primary_color; /**< color that a subtitle will normally appear in */
  41. int secondary_color;
  42. int outline_color; /**< color for outline in ASS, called tertiary in SSA */
  43. int back_color; /**< color of the subtitle outline or shadow */
  44. int bold; /**< whether text is bold (1) or not (0) */
  45. int italic; /**< whether text is italic (1) or not (0) */
  46. int underline; /**< whether text is underlined (1) or not (0) */
  47. int strikeout;
  48. float scalex;
  49. float scaley;
  50. float spacing;
  51. float angle;
  52. int border_style;
  53. float outline;
  54. float shadow;
  55. int alignment; /**< position of the text (left, center, top...),
  56. defined after the layout of the numpad
  57. (1-3 sub, 4-6 mid, 7-9 top) */
  58. int margin_l;
  59. int margin_r;
  60. int margin_v;
  61. int alpha_level;
  62. int encoding;
  63. } ASSStyle;
  64. /**
  65. * fields extracted from the [Events] section
  66. */
  67. typedef struct {
  68. int layer; /**< higher numbered layers are drawn over lower numbered */
  69. int start; /**< start time of the dialog in centiseconds */
  70. int end; /**< end time of the dialog in centiseconds */
  71. char *style; /**< name of the ASSStyle to use with this dialog */
  72. char *name;
  73. int margin_l;
  74. int margin_r;
  75. int margin_v;
  76. char *effect;
  77. char *text; /**< actual text which will be displayed as a subtitle,
  78. can include style override control codes (see
  79. ff_ass_split_override_codes()) */
  80. } ASSDialog;
  81. /**
  82. * structure containing the whole split ASS data
  83. */
  84. typedef struct {
  85. ASSScriptInfo script_info; /**< general information about the SSA script*/
  86. ASSStyle *styles; /**< array of split out styles */
  87. int styles_count; /**< number of ASSStyle in the styles array */
  88. ASSDialog *dialogs; /**< array of split out dialogs */
  89. int dialogs_count; /**< number of ASSDialog in the dialogs array*/
  90. } ASS;
  91. /**
  92. * This struct can be casted to ASS to access to the split data.
  93. */
  94. typedef struct ASSSplitContext ASSSplitContext;
  95. /**
  96. * Split a full ASS file or a ASS header from a string buffer and store
  97. * the split structure in a newly allocated context.
  98. *
  99. * @param buf String containing the ASS formatted data.
  100. * @return Newly allocated struct containing split data.
  101. */
  102. ASSSplitContext *ff_ass_split(const char *buf);
  103. /**
  104. * Split one or several ASS "Dialogue" lines from a string buffer and store
  105. * them in a already initialized context.
  106. *
  107. * @param ctx Context previously initialized by ff_ass_split().
  108. * @param buf String containing the ASS "Dialogue" lines.
  109. * @param cache Set to 1 to keep all the previously split ASSDialog in
  110. * the context, or set to 0 to free all the previously split
  111. * ASSDialog.
  112. * @param number If not NULL, the pointed integer will be set to the number
  113. * of split ASSDialog.
  114. * @return Pointer to the first split ASSDialog.
  115. */
  116. ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf,
  117. int cache, int *number);
  118. /**
  119. * Free all the memory allocated for an ASSSplitContext.
  120. *
  121. * @param ctx Context previously initialized by ff_ass_split().
  122. */
  123. void ff_ass_split_free(ASSSplitContext *ctx);
  124. /**
  125. * Set of callback functions corresponding to each override codes that can
  126. * be encountered in a "Dialogue" Text field.
  127. */
  128. typedef struct {
  129. /**
  130. * @defgroup ass_styles ASS styles
  131. * @{
  132. */
  133. void (*text)(void *priv, const char *text, int len);
  134. void (*new_line)(void *priv, int forced);
  135. void (*style)(void *priv, char style, int close);
  136. void (*color)(void *priv, unsigned int /* color */, unsigned int color_id);
  137. void (*alpha)(void *priv, int alpha, int alpha_id);
  138. void (*font_name)(void *priv, const char *name);
  139. void (*font_size)(void *priv, int size);
  140. void (*alignment)(void *priv, int alignment);
  141. void (*cancel_overrides)(void *priv, const char *style);
  142. /** @} */
  143. /**
  144. * @defgroup ass_functions ASS functions
  145. * @{
  146. */
  147. void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
  148. void (*origin)(void *priv, int x, int y);
  149. /** @} */
  150. /**
  151. * @defgroup ass_end end of Dialogue Event
  152. * @{
  153. */
  154. void (*end)(void *priv);
  155. /** @} */
  156. } ASSCodesCallbacks;
  157. /**
  158. * Split override codes out of a ASS "Dialogue" Text field.
  159. *
  160. * @param callbacks Set of callback functions called for each override code
  161. * encountered.
  162. * @param priv Opaque pointer passed to the callback functions.
  163. * @param buf The ASS "Dialogue" Text field to split.
  164. * @return >= 0 on success otherwise an error code <0
  165. */
  166. int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
  167. const char *buf);
  168. /**
  169. * Find an ASSStyle structure by its name.
  170. *
  171. * @param ctx Context previously initialized by ff_ass_split().
  172. * @param style name of the style to search for.
  173. * @return the ASSStyle corresponding to style, or NULL if style can't be found
  174. */
  175. ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style);
  176. #endif /* AVCODEC_ASS_SPLIT_H */