-
Notifications
You must be signed in to change notification settings - Fork 2
/
ttml_patch.txt
362 lines (356 loc) · 13 KB
/
ttml_patch.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
diff -Naur ccextractor.0.63/src/608.cpp ccextractor.0.63.jk/src/608.cpp
--- ccextractor.0.63/src/608.cpp 2012-08-16 05:15:32.000000000 -0400
+++ ccextractor.0.63.jk/src/608.cpp 2012-09-20 12:18:36.000000000 -0400
@@ -53,6 +53,11 @@
</HEAD>\n\n\
<BODY>\n";
+const char *smptett_header =
+"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\
+<tt xmlns=\"http://www.w3.org/ns/ttml\" xml:lang=\"en\">\n\
+<body>\n<div>\n" ;
+
const char *command_type[] =
{
"Unknown",
@@ -209,19 +214,28 @@
void write_subtitle_file_footer (struct s_write *wb)
{
- switch (write_format)
+ switch (write_format)
{
- case OF_SAMI:
- sprintf ((char *) str,"</BODY></SAMI>\n");
- if (encoding!=ENC_UNICODE)
- {
- dbg_print(DMT_608, "\r%s\n", str);
- }
- enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
- write (wb->fh, enc_buffer,enc_buffer_used);
- break;
- default: // Nothing to do. Only SAMI has a footer
- break;
+ case OF_SAMI:
+ sprintf ((char *) str,"</BODY></SAMI>\n");
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ break;
+ case OF_SMPTETT:
+ sprintf ((char *) str,"</div></body></tt>\n");
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ break;
+ default: // Nothing to do. Only SAMI has a footer
+ break;
}
}
@@ -238,6 +252,12 @@
enc_buffer_used=encode_line (enc_buffer,(unsigned char *) sami_header);
write (wb->fh, enc_buffer,enc_buffer_used);
break;
+ case OF_SMPTETT: // This header brought to you by McPoodle's CCASDI
+ //fprintf_encoded (wb->fh, sami_header);
+ GUARANTEE(strlen (smptett_header)*3);
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) smptett_header);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ break;
case OF_RCWT: // Write header
write (wb->fh, rcwt_header, sizeof(rcwt_header));
break;
@@ -345,6 +365,11 @@
try_to_add_start_credits(wb);
wrote_something = write_cc_buffer_as_sami (data,wb);
break;
+ case OF_SMPTETT:
+ if (!startcredits_displayed && start_credits_text!=NULL)
+ try_to_add_start_credits(wb);
+ wrote_something = write_cc_buffer_as_smptett (data,wb);
+ break;
case OF_TRANSCRIPT:
wrote_something = write_cc_buffer_as_transcript (data,wb);
break;
diff -Naur ccextractor.0.63/src/608.h ccextractor.0.63.jk/src/608.h
--- ccextractor.0.63/src/608.h 2012-08-16 05:15:33.000000000 -0400
+++ ccextractor.0.63.jk/src/608.h 2012-09-12 15:48:18.000000000 -0400
@@ -19,6 +19,8 @@
void correct_case (int line_num, struct eia608_screen *data);
int write_cc_buffer_as_sami (struct eia608_screen *data, struct s_write *wb);
void write_stringz_as_sami (char *string, struct s_write *wb, LLONG ms_start, LLONG ms_end);
+int write_cc_buffer_as_smptett (struct eia608_screen *data, struct s_write *wb);
+void write_stringz_as_smptett (char *string, struct s_write *wb, LLONG ms_start, LLONG ms_end);
unsigned encode_line (unsigned char *buffer, unsigned char *text);
void correct_case (int line_num, struct eia608_screen *data);
void capitalize (int line_num, struct eia608_screen *data);
diff -Naur ccextractor.0.63/src/608_helpers.cpp ccextractor.0.63.jk/src/608_helpers.cpp
--- ccextractor.0.63/src/608_helpers.cpp 2012-08-16 05:15:34.000000000 -0400
+++ ccextractor.0.63.jk/src/608_helpers.cpp 2012-09-12 15:33:26.000000000 -0400
@@ -354,6 +354,9 @@
case OF_SAMI:
write_stringz_as_sami(end_credits_text,wb,st,end);
break;
+ case OF_SMPTETT:
+ write_stringz_as_smptett(end_credits_text,wb,st,end);
+ break ;
default:
// Do nothing for the rest
break;
@@ -406,6 +409,9 @@
case OF_SAMI:
write_stringz_as_sami(start_credits_text,wb,st,end);
break;
+ case OF_SMPTETT:
+ write_stringz_as_smptett(start_credits_text,wb,st,end);
+ break;
default:
// Do nothing for the rest
break;
diff -Naur ccextractor.0.63/src/608_smptett.cpp ccextractor.0.63.jk/src/608_smptett.cpp
--- ccextractor.0.63/src/608_smptett.cpp 1969-12-31 19:00:00.000000000 -0500
+++ ccextractor.0.63.jk/src/608_smptett.cpp 2012-11-19 12:36:08.000000000 -0500
@@ -0,0 +1,156 @@
+#include "ccextractor.h"
+
+// Produces minimally-compliant SMPTE Timed Text (W3C TTML)
+// format-compatible output
+
+// See http://www.w3.org/TR/ttaf1-dfxp/ and
+// https://www.smpte.org/sites/default/files/st2052-1-2010.pdf
+
+// Copyright (C) 2012 John Kemp
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+void write_stringz_as_smptett (char *string, struct s_write *wb, LLONG ms_start, LLONG ms_end)
+{
+ unsigned h1,m1,s1,ms1;
+ unsigned h2,m2,s2,ms2;
+
+ mstotime (ms_start,&h1,&m1,&s1,&ms1);
+ mstotime (ms_end-1,&h2,&m2,&s2,&ms2);
+
+ sprintf ((char *) str,"<p begin=\"%02u:%02u:%02u,%03u\" end=\"%02u:%02u:%02u,%03u\">\r\n",h1,m1,s1,ms1, h2,m2,s2,ms2);
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ int len=strlen (string);
+ unsigned char *unescaped= (unsigned char *) malloc (len+1);
+ unsigned char *el = (unsigned char *) malloc (len*3+1); // Be generous
+ if (el==NULL || unescaped==NULL)
+ fatal (EXIT_NOT_ENOUGH_MEMORY, "In write_stringz_as_sami() - not enough memory.\n");
+ int pos_r=0;
+ int pos_w=0;
+ // Scan for \n in the string and replace it with a 0
+ while (pos_r<len)
+ {
+ if (string[pos_r]=='\\' && string[pos_r+1]=='n')
+ {
+ unescaped[pos_w]=0;
+ pos_r+=2;
+ }
+ else
+ {
+ unescaped[pos_w]=string[pos_r];
+ pos_r++;
+ }
+ pos_w++;
+ }
+ unescaped[pos_w]=0;
+ // Now read the unescaped string (now several string'z and write them)
+ unsigned char *begin=unescaped;
+ while (begin<unescaped+len)
+ {
+ unsigned int u = encode_line (el, begin);
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r");
+ dbg_print(DMT_608, "%s\n",subline);
+ }
+ write (wb->fh, el, u);
+ //write (wb->fh, encoded_br, encoded_br_length);
+
+ write (wb->fh, encoded_crlf, encoded_crlf_length);
+ begin+= strlen ((const char *) begin)+1;
+ }
+
+ sprintf ((char *) str,"</p>\n");
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ sprintf ((char *) str,"<p begin=\"%02u:%02u:%02u,%03u\">\n\n",h2,m2,s2,ms2);
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ sprintf ((char *) str,"</p>\n");
+}
+
+
+
+int write_cc_buffer_as_smptett (struct eia608_screen *data, struct s_write *wb)
+{
+ unsigned h1,m1,s1,ms1;
+ unsigned h2,m2,s2,ms2;
+ int wrote_something=0;
+ LLONG startms = wb->data608->current_visible_start_ms;
+
+ startms+=subs_delay;
+ if (startms<0) // Drop screens that because of subs_delay start too early
+ return 0;
+
+ LLONG endms = get_visible_end()+subs_delay;
+ endms--; // To prevent overlapping with next line.
+ mstotime (startms,&h1,&m1,&s1,&ms1);
+ mstotime (endms-1,&h2,&m2,&s2,&ms2);
+
+ sprintf ((char *) str,"<p begin=\"%02u:%02u:%02u,%03u\" end=\"%02u:%02u:%02u,%03u\">\n",h1,m1,s1,ms1, h2,m2,s2,ms2);
+
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+ for (int i=0;i<15;i++)
+ {
+ if (data->row_used[i])
+ {
+ int length = get_decoder_line_encoded (subline, i, data);
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r");
+ dbg_print(DMT_608, "%s\n",subline);
+ }
+ write (wb->fh, subline, length);
+ wrote_something=1;
+ //if (i!=14)
+ //write (wb->fh, encoded_br, encoded_br_length);
+ write (wb->fh,encoded_crlf, encoded_crlf_length);
+ }
+ }
+ sprintf ((char *) str,"</p>\n");
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ write (wb->fh, enc_buffer,enc_buffer_used);
+
+ if (encoding!=ENC_UNICODE)
+ {
+ dbg_print(DMT_608, "\r%s\n", str);
+ }
+ enc_buffer_used=encode_line (enc_buffer,(unsigned char *) str);
+ //write (wb->fh, enc_buffer,enc_buffer_used);
+
+ return wrote_something;
+}
diff -Naur ccextractor.0.63/src/ccextractor.cpp ccextractor.0.63.jk/src/ccextractor.cpp
--- ccextractor.0.63/src/ccextractor.cpp 2012-08-16 05:33:10.000000000 -0400
+++ ccextractor.0.63.jk/src/ccextractor.cpp 2012-09-12 15:40:53.000000000 -0400
@@ -238,6 +238,9 @@
case OF_SAMI:
extension = ".smi";
break;
+ case OF_SMPTETT:
+ extension = ".ttml";
+ break;
case OF_TRANSCRIPT:
extension = ".txt";
break;
@@ -659,7 +662,7 @@
if (wbout1.fh!=-1)
{
- if (write_format==OF_SAMI || write_format==OF_SRT || write_format==OF_TRANSCRIPT)
+ if (write_format==OF_SMPTETT || write_format==OF_SAMI || write_format==OF_SRT || write_format==OF_TRANSCRIPT)
{
handle_end_of_data (&wbout1);
}
@@ -674,7 +677,7 @@
}
if (wbout2.fh!=-1)
{
- if (write_format==OF_SAMI || write_format==OF_SRT || write_format==OF_TRANSCRIPT)
+ if (write_format==OF_SMPTETT || write_format==OF_SAMI || write_format==OF_SRT || write_format==OF_TRANSCRIPT)
{
handle_end_of_data (&wbout2);
}
diff -Naur ccextractor.0.63/src/ccextractor.h ccextractor.0.63.jk/src/ccextractor.h
--- ccextractor.0.63/src/ccextractor.h 2012-08-16 05:33:10.000000000 -0400
+++ ccextractor.0.63.jk/src/ccextractor.h 2012-09-12 12:09:45.000000000 -0400
@@ -121,12 +121,13 @@
enum output_format
{
- OF_RAW = 0,
- OF_SRT = 1,
- OF_SAMI = 2,
- OF_TRANSCRIPT = 3,
- OF_RCWT = 4,
- OF_NULL = 5
+ OF_RAW = 0,
+ OF_SRT = 1,
+ OF_SAMI = 2,
+ OF_TRANSCRIPT = 3,
+ OF_RCWT = 4,
+ OF_NULL = 5,
+ OF_SMPTETT = 6
};
enum stream_mode_enum
@@ -701,4 +702,4 @@
extern uint32_t tlt_frames_produced;
void tlt_process_pes_packet(uint8_t *buffer, uint16_t size) ;
void telxcc_init(void);
-void telxcc_close(void);
\ No newline at end of file
+void telxcc_close(void);
diff -Naur ccextractor.0.63/src/output.cpp ccextractor.0.63.jk/src/output.cpp
--- ccextractor.0.63/src/output.cpp 2012-08-16 05:15:40.000000000 -0400
+++ ccextractor.0.63.jk/src/output.cpp 2012-09-12 15:41:38.000000000 -0400
@@ -32,7 +32,8 @@
if (wb)
writeraw (data,length,wb);
}
- else if (write_format==OF_SAMI ||
+ else if (write_format==OF_SMPTETT ||
+ write_format==OF_SAMI ||
write_format==OF_SRT ||
write_format==OF_TRANSCRIPT ||
write_format==OF_NULL)
diff -Naur ccextractor.0.63/src/params.cpp ccextractor.0.63.jk/src/params.cpp
--- ccextractor.0.63/src/params.cpp 2012-08-16 05:15:42.000000000 -0400
+++ ccextractor.0.63.jk/src/params.cpp 2012-09-12 12:02:38.000000000 -0400
@@ -281,6 +281,8 @@
write_format=OF_RAW;
rawmode=1;
}
+ else if (strcmp (format, "smptett")==0)
+ write_format=OF_SMPTETT ;
else
fatal (EXIT_MALFORMED_PARAMETER, "Unknown output file format: %s\n", format);
}