1 /*
2 * SubRip subtitle encoder
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
22 #include <stdarg.h>
28
29
30 #define SRT_STACK_SIZE 64
31
42
43
44 #ifdef __GNUC__
45 __attribute__ ((__format__ (__printf__, 2, 3)))
46 #endif
48 {
49 va_list vargs;
50 va_start(vargs, str);
52 va_end(vargs);
53 }
54
56 {
58 return -1;
60 return 0;
61 }
62
64 {
66 return 0;
68 }
69
71 {
72 int i;
75 break;
76 return i;
77 }
78
80 {
81 srt_print(s,
"</%c%s>", tag, tag ==
'f' ?
"ont" :
"");
82 }
83
85 {
86 if (close) {
88 if (i < 0)
89 return;
94 }
95
97 {
99 if (st) {
111 (c & 0xFF0000) >> 16 | c & 0xFF00 | (c & 0xFF) << 16);
114 }
118 }
122 }
126 }
130 }
131 }
132 }
133
134
136 {
142 }
143
145 {
148 }
149
151 {
153 }
154
156 {
158 if (!close)
160 }
161
163 {
164 if (color_id > 1)
165 return;
167 if (color != 0xFFFFFFFF)
168 srt_print(priv,
"<font color=\"#%06x\">",
169 (color & 0xFF0000) >> 16 | color & 0xFF00 | (color & 0xFF) << 16);
170 }
171
173 {
175 if (name)
176 srt_print(priv,
"<font face=\"%s\">", name);
177 }
178
180 {
182 if (size >= 0)
183 srt_print(priv,
"<font size=\"%d\">", size);
184 }
185
187 {
192 }
193 }
194
196 {
199 }
200
201 static void srt_move_cb(
void *priv,
int x1,
int y1,
int x2,
int y2,
203 {
205
209 " X1:%03u X2:%03u Y1:%03u Y2:%03u", x1, x2, y1, y2);
210 unsigned char *
dummy;
211 unsigned room;
212
214 if (room >= len) {
219 }
220 /* Increment even if av_bprint_get_buffer() did not return enough room:
221 the bprint structure will be treated as truncated. */
223 }
224 }
225
227 {
229
233 }
234
246 };
247
250 {
253 int i, num;
254
256
258
262 }
263
265 for (; dialog && num--; dialog++) {
267 int sh, sm, ss, sc = 10 * dialog->
start;
268 int eh, em, es, ec = 10 * dialog->
end;
269 sh = sc/3600000; sc -= 3600000*sh;
270 sm = sc/ 60000; sc -= 60000*sm;
271 ss = sc/ 1000; sc -= 1000*ss;
272 eh = ec/3600000; ec -= 3600000*eh;
273 em = ec/ 60000; ec -= 60000*em;
274 es = ec/ 1000; ec -= 1000*es;
275 srt_print(s,
"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n",
276 ++s->
count, sh, sm, ss, sc, eh, em, es, ec);
278 }
282 }
283 }
284
288 return 0;
289
290 if (s->
buffer.len > bufsize) {
292 return -1;
293 }
295
297 }
298
300 {
304 return 0;
305 }
306
307 #if CONFIG_SRT_ENCODER
308 /* deprecated encoder */
318 };
319 #endif
320
321 #if CONFIG_SUBRIP_ENCODER
331 };
332 #endif