1 /*
2 * MCC subtitle demuxer
3 * Copyright (c) 2020 Paul B Mahol
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
28
32
34 {
35 char buf[28];
37
39
42
44
45 if (!memcmp(buf, "File Format=MacCaption_MCC V", 28))
47
48 return 0;
49 }
50
52 {
53 if (x >= 'a')
54 x -= 87;
55 else if (x >= 'A')
56 x -= 55;
57 else
58 x -= '0';
59 return x;
60 }
61
67
69 { .
key = 16, .len = 3, .value =
"\xFA\x0\x0", },
70 { .key = 17, .len = 6, .value = "\xFA\x0\x0\xFA\x0\x0", },
71 { .key = 18, .len = 9, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
72 { .key = 19, .len = 12, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
73 { .key = 20, .len = 15, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
74 { .key = 21, .len = 18, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
75 { .key = 22, .len = 21, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
76 { .key = 23, .len = 24, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
77 { .key = 24, .len = 27, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
78 { .key = 25, .len = 3, .value = "\xFB\x80\x80", },
79 { .key = 26, .len = 3, .value = "\xFC\x80\x80", },
80 { .key = 27, .len = 3, .value = "\xFD\x80\x80", },
81 { .key = 28, .len = 2, .value = "\x96\x69", },
82 { .key = 29, .len = 2, .value = "\x61\x01", },
83 { .key = 30, .len = 3, .value = "\xFC\x80\x80", },
84 { .key = 31, .len = 3, .value = "\xFC\x80\x80", },
85 { .key = 32, .len = 4, .value = "\xE1\x00\x00\x00", },
86 { .key = 33, .len = 0, .value =
NULL, },
87 { .key = 34, .len = 0, .value =
NULL, },
88 { .key = 35, .len = 1, .value = "\x0", },
89 };
90
92 {
101
103
104 if (!st)
109
111 int hh, mm,
ss,
fs,
i = 0, j = 0;
112 int start = 12, count = 0;
114 char *lline;
115
117 if (!strncmp(
line,
"File Format=MacCaption_MCC V", 28))
118 continue;
119 if (!strncmp(
line,
"//", 2))
120 continue;
121 if (!strncmp(
line,
"Time Code Rate=", 15)) {
122 char *rate_str =
line + 15;
124 int num = -1, den = -1;
125
126 if (rate_str[0]) {
127 num = strtol(rate_str, &
df, 10);
128 den = 1;
130 av_reduce(&num, &den, num * 1000LL, 1001, INT_MAX);
131 }
132 }
133
134 if (num > 0 && den > 0) {
137 }
138 continue;
139 }
140
142 continue;
143
145
146 lline = (
char *)&
line;
147 lline += 12;
149
152
153 if (v >= 16 && v <= 35) {
154 int idx = v - 16;
157 j = 0;
158 break;
159 }
162 }
163 } else {
164 uint8_t vv;
165
166 if (
i + 13 >=
sizeof(
line) - 1)
167 break;
169 if (j >=
sizeof(
out) - 1) {
170 j = 0;
171 break;
172 }
173 out[j++] = vv | (v << 4);
175 }
176
178 }
180
182 start += 4;
183 count = (
out[11] & 0x1f) * 3;
184 if (j < start + count + 1)
185 continue;
186
187 if (!count)
188 continue;
192
196 }
197
199
201 }
202
210 .extensions = "mcc",
214 };