1 /*
2 * WebVTT subtitle encoder
3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
4 * Copyright (c) 2014 Aman Gupta <ffmpeg@tmm1.net>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <stdarg.h>
29
30 #define WEBVTT_STACK_SIZE 64
40
41 #ifdef __GNUC__
42 __attribute__ ((__format__ (__printf__, 2, 3)))
43 #endif
45 {
46 va_list vargs;
47 va_start(vargs, str);
49 va_end(vargs);
50 }
51
53 {
55 return -1;
57 return 0;
58 }
59
61 {
63 return 0;
65 }
66
68 {
69 int i;
72 break;
73 return i;
74 }
75
77 {
79 }
80
82 {
83 if (close) {
85 if (i < 0)
86 return;
91 }
92
94 {
96 if (st) {
100 }
104 }
108 }
109 }
110 }
111
113 {
116 }
117
119 {
121 }
122
124 {
125 if (style == 's') // strikethrough unsupported
126 return;
127
129 if (!close)
131 }
132
134 {
137 }
138
140 {
142 }
143
155 };
156
159 {
162 int i;
163
165
167 const char *ass = sub->
rects[i]->
ass;
168
172 }
173
174 #if FF_API_ASS_TIMING
175 if (!strncmp(ass, "Dialogue: ", 10)) {
176 int num;
178 // TODO reindent
179 for (; dialog && num--; dialog++) {
182 }
183 } else {
184 #endif
186 if (!dialog)
191 #if FF_API_ASS_TIMING
192 }
193 #endif
194 }
195
199 return 0;
200
201 if (s->
buffer.len > bufsize) {
203 return -1;
204 }
206
208 }
209
211 {
215 return 0;
216 }
217
219 {
225 }
226
236 };
AVCodec ff_webvtt_encoder
char * style
name of the ASSStyle to use with this dialog
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
char stack[WEBVTT_STACK_SIZE]
fields extracted from the [Events] section
static int webvtt_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
static void webvtt_stack_push_pop(WebVTTContext *s, const char c, int close)
static av_cold int init(AVCodecContext *avctx)
ASSDialog * ff_ass_split_dialog2(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
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...
static void webvtt_style_cb(void *priv, char style, int close)
static void webvtt_print(WebVTTContext *s, const char *str,...)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static void webvtt_cancel_overrides_cb(void *priv, const char *style)
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
This struct can be casted to ASS to access to the split data.
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog2().
int bold
whether text is bold (1) or not (0)
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
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...
static void webvtt_end_cb(void *priv)
#define ASS_DEFAULT_UNDERLINE
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_BPRINT_SIZE_UNLIMITED
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
const char * name
Name of the codec implementation.
static int webvtt_stack_push(WebVTTContext *s, const char c)
static av_cold int webvtt_encode_init(AVCodecContext *avctx)
static void webvtt_text_cb(void *priv, const char *text, int len)
void(* text)(void *priv, const char *text, int len)
int italic
whether text is italic (1) or not (0)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
static void webvtt_close_tag(WebVTTContext *s, char tag)
static void webvtt_new_line_cb(void *priv, int forced)
static char webvtt_stack_pop(WebVTTContext *s)
Libavcodec external API header.
static int webvtt_encode_close(AVCodecContext *avctx)
main external API structure.
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
fields extracted from the [V4(+) Styles] section
ASSSplitContext * ass_ctx
static void webvtt_style_apply(WebVTTContext *s, const char *style)
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Formatted text, the ass field must be set by the decoder and is authoritative.
#define ASS_DEFAULT_ITALIC
char * ass
0 terminated ASS/SSA compatible event line.
void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
#define WEBVTT_STACK_SIZE
static int webvtt_stack_find(WebVTTContext *s, const char c)
int underline
whether text is underlined (1) or not (0)
static const ASSCodesCallbacks webvtt_callbacks
uint8_t * subtitle_header
Header containing style information for text subtitles.