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.

173 lines
6.3KB

  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 back_color; /**< color of the subtitle outline or shadow */
  42. int bold; /**< whether text is bold (1) or not (0) */
  43. int italic; /**< whether text is italic (1) or not (0) */
  44. int underline; /**< whether text is underlined (1) or not (0) */
  45. int alignment; /**< position of the text (left, center, top...),
  46. defined after the layout of the numpad
  47. (1-3 sub, 4-6 mid, 7-9 top) */
  48. } ASSStyle;
  49. /**
  50. * fields extracted from the [Events] section
  51. */
  52. typedef struct {
  53. int layer; /**< higher numbered layers are drawn over lower numbered */
  54. int start; /**< start time of the dialog in centiseconds */
  55. int end; /**< end time of the dialog in centiseconds */
  56. char *style; /**< name of the ASSStyle to use with this dialog */
  57. char *text; /**< actual text which will be displayed as a subtitle,
  58. can include style override control codes (see
  59. ff_ass_split_override_codes()) */
  60. } ASSDialog;
  61. /**
  62. * structure containing the whole split ASS data
  63. */
  64. typedef struct {
  65. ASSScriptInfo script_info; /**< general information about the SSA script*/
  66. ASSStyle *styles; /**< array of split out styles */
  67. int styles_count; /**< number of ASSStyle in the styles array */
  68. ASSDialog *dialogs; /**< array of split out dialogs */
  69. int dialogs_count; /**< number of ASSDialog in the dialogs array*/
  70. } ASS;
  71. /**
  72. * This struct can be casted to ASS to access to the split data.
  73. */
  74. typedef struct ASSSplitContext ASSSplitContext;
  75. /**
  76. * Split a full ASS file or a ASS header from a string buffer and store
  77. * the split structure in a newly allocated context.
  78. *
  79. * @param buf String containing the ASS formated data.
  80. * @return Newly allocated struct containing split data.
  81. */
  82. ASSSplitContext *ff_ass_split(const char *buf);
  83. /**
  84. * Split one or several ASS "Dialogue" lines from a string buffer and store
  85. * them in a already initialized context.
  86. *
  87. * @param ctx Context previously initialized by ff_ass_split().
  88. * @param buf String containing the ASS "Dialogue" lines.
  89. * @param cache Set to 1 to keep all the previously split ASSDialog in
  90. * the context, or set to 0 to free all the previously split
  91. * ASSDialog.
  92. * @param number If not NULL, the pointed integer will be set to the number
  93. * of split ASSDialog.
  94. * @return Pointer to the first split ASSDialog.
  95. */
  96. ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf,
  97. int cache, int *number);
  98. /**
  99. * Free all the memory allocated for an ASSSplitContext.
  100. *
  101. * @param ctx Context previously initialized by ff_ass_split().
  102. */
  103. void ff_ass_split_free(ASSSplitContext *ctx);
  104. /**
  105. * Set of callback functions corresponding to each override codes that can
  106. * be encountered in a "Dialogue" Text field.
  107. */
  108. typedef struct {
  109. /**
  110. * @defgroup ass_styles ASS styles
  111. * @{
  112. */
  113. void (*text)(void *priv, const char *text, int len);
  114. void (*new_line)(void *priv, int forced);
  115. void (*style)(void *priv, char style, int close);
  116. void (*color)(void *priv, unsigned int color, unsigned int color_id);
  117. void (*alpha)(void *priv, int alpha, int alpha_id);
  118. void (*font_name)(void *priv, const char *name);
  119. void (*font_size)(void *priv, int size);
  120. void (*alignment)(void *priv, int alignment);
  121. void (*cancel_overrides)(void *priv, const char *style);
  122. /** @} */
  123. /**
  124. * @defgroup ass_functions ASS functions
  125. * @{
  126. */
  127. void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
  128. void (*origin)(void *priv, int x, int y);
  129. /** @} */
  130. /**
  131. * @defgroup ass_end end of Dialogue Event
  132. * @{
  133. */
  134. void (*end)(void *priv);
  135. /** @} */
  136. } ASSCodesCallbacks;
  137. /**
  138. * Split override codes out of a ASS "Dialogue" Text field.
  139. *
  140. * @param callbacks Set of callback functions called for each override code
  141. * encountered.
  142. * @param priv Opaque pointer passed to the callback functions.
  143. * @param buf The ASS "Dialogue" Text field to split.
  144. * @return >= 0 on success otherwise an error code <0
  145. */
  146. int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
  147. const char *buf);
  148. /**
  149. * Find an ASSStyle structure by its name.
  150. *
  151. * @param ctx Context previously initialized by ff_ass_split().
  152. * @param style name of the style to search for.
  153. * @return the ASSStyle corresponding to style, or NULL if style can't be found
  154. */
  155. ASSStyle *ass_style_get(ASSSplitContext *ctx, const char *style);
  156. #endif /* AVCODEC_ASS_SPLIT_H */