Bump micro for VP8 emu-edge support.
[libav.git] / libavcodec / ass.c
CommitLineData
5952be07
AJ
1/*
2 * SSA/ASS common funtions
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 "avcodec.h"
23#include "ass.h"
24
25void ff_ass_init(AVSubtitle *sub)
26{
27 memset(sub, 0, sizeof(*sub));
28}
29
30static int ts_to_string(char *str, int strlen, int ts)
31{
32 int h, m, s;
33 h = ts/360000; ts -= 360000*h;
34 m = ts/ 6000; ts -= 6000*m;
35 s = ts/ 100; ts -= 100*s;
36 return snprintf(str, strlen, "%d:%02d:%02d.%02d", h, m, s, ts);
37}
38
39int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
40 int ts_start, int ts_end, int raw)
41{
42 int len = 0, dlen, duration = ts_end - ts_start;
43 char s_start[16], s_end[16], header[48] = {0};
44 AVSubtitleRect **rects;
45
46 if (!raw) {
47 ts_to_string(s_start, sizeof(s_start), ts_start);
48 ts_to_string(s_end, sizeof(s_end), ts_end );
49 len = snprintf(header, sizeof(header), "Dialogue: 0,%s,%s,",
50 s_start, s_end);
51 }
52
53 dlen = strcspn(dialog, "\n");
54 dlen += dialog[dlen] == '\n';
55
56 rects = av_realloc(sub->rects, (sub->num_rects+1) * sizeof(*sub->rects));
57 if (!rects)
58 return AVERROR(ENOMEM);
59 sub->rects = rects;
60 sub->end_display_time = FFMAX(sub->end_display_time, 10 * duration);
61 rects[sub->num_rects] = av_mallocz(sizeof(*rects[0]));
62 rects[sub->num_rects]->type = SUBTITLE_ASS;
63 rects[sub->num_rects]->ass = av_malloc(len + dlen + 1);
64 strcpy (rects[sub->num_rects]->ass , header);
65 strncpy(rects[sub->num_rects]->ass + len, dialog, dlen);
4ab4d65f 66 rects[sub->num_rects]->ass[len+dlen] = 0;
5952be07
AJ
67 sub->num_rects++;
68 return dlen;
69}