1 /*
2 * SubRip subtitle demuxer
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
27
28 typedef struct {
31
33 {
37
39
42
43 /* Check if the first non-empty line is a number. We do not check what the
44 * number is because in practice it can be anything. */
46 strtol(buf, &pbuf, 10) < 0 || *pbuf)
47 return 0;
48
49 /* Check if the next line matches a SRT timestamp */
51 return 0;
52 if (buf[0] >= '0' && buf[1] <= '9' && strstr(buf, " --> ")
53 && sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1)
55
56 return 0;
57 }
58
61 {
62 int i;
63
64 for (i=0; i<2; i++) {
65 int hh1, mm1, ss1, ms1;
66 int hh2, mm2, ss2, ms2;
67 if (sscanf(*buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d"
68 "%*[ ]X1:%u X2:%u Y1:%u Y2:%u",
69 &hh1, &mm1, &ss1, &ms1,
70 &hh2, &mm2, &ss2, &ms2,
71 x1, x2, y1, y2) >= 8) {
72 int64_t
start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1;
73 int64_t
end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2;
74 *duration = end -
start;
77 }
79 }
81 }
82
84 {
88 int res = 0;
91
92 if (!st)
97
99
102
103 if (buf.len) {
107 const char *ptr = buf.str;
108 int32_t x1 = -1, y1 = -1, x2 = -1, y2 = -1;
110
111 pts =
get_pts(&ptr, &duration, &x1, &y1, &x2, &y2);
113 int len = buf.len - (ptr - buf.str);
114 if (len <= 0)
115 continue;
117 if (!sub) {
120 }
124 if (x1 != -1) {
126 if (p) {
131 }
132 }
133 }
134 }
135 }
136
138
141 return res;
142 }
143
145 {
148 }
149
151 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
152 {
155 min_ts, ts, max_ts, flags);
156 }
157
159 {
162 return 0;
163 }
164
174 };