1 /*
2 * TTML subtitle muxer
3 * Copyright (c) 2020 24i
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 /**
23 * @file
24 * TTML subtitle muxer
25 * @see https://www.w3.org/TR/ttml1/
26 * @see https://www.w3.org/TR/ttml2/
27 * @see https://www.w3.org/TR/ttml-imsc/rec
28 */
29
36
40 };
41
45 };
46
51
53 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
54 "<tt\n"
55 "%s"
56 " xml:lang=\"%s\">\n"
57 "%s"
58 " <body>\n"
59 " <div>\n";
60
62 " </div>\n"
63 " </body>\n"
64 "</tt>\n";
65
67 int64_t millisec)
68 {
69 int64_t sec,
min, hour;
70 sec = millisec / 1000;
71 millisec -= 1000 * sec;
76
77 avio_printf(pb,
"%s=\"%02"PRId64
":%02"PRId64
":%02"PRId64
".%03"PRId64
"\"",
78 tag, hour,
min, sec, millisec);
79 }
80
83 {
84 size_t additional_data_size =
90
91 if (!additional_data_size) {
92 // simple case, we don't have to go through local_params and just
93 // set default fall-back values (for old extradata format).
96
97 return 0;
98 }
99
100 if (value_size == additional_data_size ||
101 value[value_size] !=
'0円')
103
105
106 additional_data_size -= value_size + 1;
107 value += value_size + 1;
108 if (!additional_data_size)
110
112 if (value_size == additional_data_size ||
113 value[value_size] !=
'0円')
115
117
118 *header_params = local_params;
119
120 return 0;
121 }
122
124 {
127
132 }
133
134 {
137
139 0);
140 const char *printed_lang = (lang && lang->
value) ? lang->
value :
"";
141
145
147
154 "Failed to parse TTML header values from extradata: "
157 }
158
161 printed_lang,
163 }
164 }
165
166 return 0;
167 }
168
170 {
173
176 // write out a paragraph element with the given contents.
184 break;
186 // dump the given document out as-is.
189 "Attempting to write multiple TTML documents into a "
190 "single document! The XML specification forbids this "
191 "as there has to be a single root tag.\n");
193 }
196 break;
197 default:
199 "Internal error: invalid TTML input packet type: %d!\n",
202 }
203
204 return 0;
205 }
206
208 {
211
214
215 return 0;
216 }
217
221 .extensions = "ttml",
222 .mime_type = "text/ttml",
230 };