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
29
33
35 {
36 char buf[28];
38
40
43
45
46 if (!memcmp(buf, "File Format=MacCaption_MCC V", 28))
48
49 return 0;
50 }
51
53 {
54 if (x >= 'a')
55 x -= 87;
56 else if (x >= 'A')
57 x -= 55;
58 else
59 x -= '0';
60 return x;
61 }
62
68
70 { .
key = 16, .len = 3, .value =
"\xFA\x0\x0", },
71 { .key = 17, .len = 6, .value = "\xFA\x0\x0\xFA\x0\x0", },
72 { .key = 18, .len = 9, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
73 { .key = 19, .len = 12, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
74 { .key = 20, .len = 15, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
75 { .key = 21, .len = 18, .value = "\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0\xFA\x0\x0", },
76 { .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", },
77 { .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", },
78 { .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", },
79 { .key = 25, .len = 3, .value = "\xFB\x80\x80", },
80 { .key = 26, .len = 3, .value = "\xFC\x80\x80", },
81 { .key = 27, .len = 3, .value = "\xFD\x80\x80", },
82 { .key = 28, .len = 2, .value = "\x96\x69", },
83 { .key = 29, .len = 2, .value = "\x61\x01", },
84 { .key = 30, .len = 3, .value = "\xFC\x80\x80", },
85 { .key = 31, .len = 3, .value = "\xFC\x80\x80", },
86 { .key = 32, .len = 4, .value = "\xE1\x00\x00\x00", },
87 { .key = 33, .len = 0, .value =
NULL, },
88 { .key = 34, .len = 0, .value =
NULL, },
89 { .key = 35, .len = 1, .value = "\x0", },
90 };
91
93 {
102
104
105 if (!st)
110
112 int hh, mm,
ss,
fs,
i = 0, j = 0;
113 int start = 12, count = 0;
115 char *lline;
116
118 if (!strncmp(
line,
"File Format=MacCaption_MCC V", 28))
119 continue;
120 if (!strncmp(
line,
"//", 2))
121 continue;
122 if (!strncmp(
line,
"Time Code Rate=", 15)) {
123 char *rate_str =
line + 15;
125 int num = -1, den = -1;
126
127 if (rate_str[0]) {
128 num = strtol(rate_str, &
df, 10);
129 den = 1;
131 av_reduce(&num, &den, num * 1000LL, 1001, INT_MAX);
132 }
133 }
134
135 if (num > 0 && den > 0) {
138 }
139 continue;
140 }
141
143 continue;
144
146
147 lline = (
char *)&
line;
148 lline += 12;
150
153
154 if (v >= 16 && v <= 35) {
155 int idx = v - 16;
158 j = 0;
159 break;
160 }
163 }
164 } else {
165 uint8_t vv;
166
167 if (
i + 13 >=
sizeof(
line) - 1)
168 break;
170 if (j >=
sizeof(
out) - 1) {
171 j = 0;
172 break;
173 }
174 out[j++] = vv | (v << 4);
176 }
177
179 }
181
183 start += 4;
184 count = (
out[11] & 0x1f) * 3;
185 if (j < start + count + 1)
186 continue;
187
188 if (!count)
189 continue;
191 if (!sub)
193
197 }
198
200
202 }
203
207 .p.extensions = "mcc",
215 };