Mercurial > mplayer.hg
annotate TOOLS/subrip.c @ 36962:6bb8d4f4a7b0
Add missing #include.
author | ib |
---|---|
date | Mon, 24 Mar 2014 11:09:39 +0000 |
parents | 1a605463f62b |
children |
rev | line source |
---|---|
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
1 /* |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
2 * Use with CVS JOCR/GOCR. |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
3 * |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
4 * You will have to change 'vobsub_id' value if you want another subtitle than number 0. |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
5 * |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
6 * HINT: you can view the subtitle that is being decoded with "display subtitle-*.pgm" |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
7 * |
30416
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
11 * (at your option) any later version. |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
12 * |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
16 * GNU General Public License for more details. |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
17 * |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
19 * with this program; if not, write to the Free Software Foundation, Inc., |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
21 */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
22 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
23 /* Make sure this accesses the CVS version of JOCR/GOCR */ |
10306
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
24 #define GOCR_PROGRAM "gocr" |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
25 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
26 #include <ctype.h> |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
27 #include <stdio.h> |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
28 #include <stdlib.h> |
23657 | 29 #include <string.h> |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
30 #include <unistd.h> |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
31 #include <sys/types.h> |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
32 #include <sys/wait.h> |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
33 #include "libvo/video_out.h" |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
32456
diff
changeset
|
34 #include "sub/vobsub.h" |
32456 | 35 #include "sub/spudec.h" |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
36 |
32244
80efcedf147d
Work around linking failure due to unresolved reference to mplayer_version.
diego
parents:
30416
diff
changeset
|
37 /* linking hacks */ |
80efcedf147d
Work around linking failure due to unresolved reference to mplayer_version.
diego
parents:
30416
diff
changeset
|
38 char *mplayer_version; |
80efcedf147d
Work around linking failure due to unresolved reference to mplayer_version.
diego
parents:
30416
diff
changeset
|
39 |
10306
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
40 /* XXX Kludge ahead, this MUST be the same as the definitions found in ../spudec.c */ |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
41 typedef struct packet_t packet_t; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
42 struct packet_t { |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
43 unsigned char *packet; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
44 unsigned int palette[4]; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
45 unsigned int alpha[4]; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
46 unsigned int control_start; /* index of start of control data */ |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
47 unsigned int current_nibble[2]; /* next data nibble (4 bits) to be |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
48 processed (for RLE decoding) for |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
49 even and odd lines */ |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
50 int deinterlace_oddness; /* 0 or 1, index into current_nibble */ |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
51 unsigned int start_col, end_col; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
52 unsigned int start_row, end_row; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
53 unsigned int width, height, stride; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
54 unsigned int start_pts, end_pts; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
55 packet_t *next; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
56 }; |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
57 typedef struct { |
10306
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
58 packet_t *queue_head; |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
59 packet_t *queue_tail; |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
60 unsigned int global_palette[16]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
61 unsigned int orig_frame_width, orig_frame_height; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
62 unsigned char* packet; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
63 size_t packet_reserve; /* size of the memory pointed to by packet */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
64 unsigned int packet_offset; /* end of the currently assembled fragment */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
65 unsigned int packet_size; /* size of the packet once all fragments are assembled */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
66 unsigned int packet_pts; /* PTS for this packet */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
67 unsigned int palette[4]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
68 unsigned int alpha[4]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
69 unsigned int cuspal[4]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
70 unsigned int custom; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
71 unsigned int now_pts; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
72 unsigned int start_pts, end_pts; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
73 unsigned int start_col, end_col; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
74 unsigned int start_row, end_row; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
75 unsigned int width, height, stride; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
76 size_t image_size; /* Size of the image buffer */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
77 unsigned char *image; /* Grayscale value */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
78 unsigned char *aimage; /* Alpha value */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
79 unsigned int scaled_frame_width, scaled_frame_height; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
80 unsigned int scaled_start_col, scaled_start_row; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
81 unsigned int scaled_width, scaled_height, scaled_stride; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
82 size_t scaled_image_size; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
83 unsigned char *scaled_image; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
84 unsigned char *scaled_aimage; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
85 int auto_palette; /* 1 if we lack a palette and must use an heuristic. */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
86 int font_start_level; /* Darkest value used for the computed font */ |
25219
e82ecde2cbd4
Mark several uses of vo_functions_t as const to stop some of the current
reimar
parents:
24234
diff
changeset
|
87 const vo_functions_t *hw_spu; |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
88 int spu_changed; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
89 } spudec_handle_t; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
90 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
91 int vobsub_id=0; |
10306
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
92 int sub_pos=0; |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
93 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
94 static spudec_handle_t *spudec; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
95 static FILE *fsub = NULL; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
96 static unsigned int sub_idx = 0; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
97 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
98 static void |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
99 process_gocr_output(const char *const fname, unsigned int start, unsigned int end) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
100 { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
101 FILE *file; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
102 int temp, h, m, s, ms; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
103 int c, bol; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
104 file = fopen(fname, "r"); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
105 if (file == NULL) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
106 perror("fopen failed"); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
107 return; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
108 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
109 temp = start; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
110 temp /= 90; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
111 h = temp / 3600000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
112 temp %= 3600000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
113 m = temp / 60000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
114 temp %= 60000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
115 s = temp / 1000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
116 temp %= 1000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
117 ms = temp; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
118 fprintf(fsub, "%d\n%02d:%02d:%02d,%03d --> ", ++sub_idx, h, m, s, ms); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
119 temp = end; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
120 temp /= 90; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
121 h = temp / 3600000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
122 temp %= 3600000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
123 m = temp / 60000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
124 temp %= 60000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
125 s = temp / 1000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
126 temp %= 1000; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
127 ms = temp; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
128 fprintf(fsub, "%02d:%02d:%02d,%03d\n", h, m, s, ms); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
129 bol = 1; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
130 while ((c = getc(file)) != EOF) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
131 if (bol) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
132 if (!isspace(c)) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
133 putc(c, fsub); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
134 bol=0; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
135 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
136 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
137 else if (!bol) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
138 putc(c, fsub); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
139 bol = c == '\n'; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
140 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
141 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
142 putc('\n', fsub); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
143 fflush(fsub); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
144 fclose(file); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
145 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
146 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
147 static void |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
148 output_pgm(FILE *f, int w, int h, unsigned char *src, unsigned char *srca, int stride) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
149 { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
150 int x, y; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
151 fprintf(f, |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
152 "P5\n" |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
153 "%d %d\n" |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
154 "255\n", |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
155 w, h); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
156 for (y = 0; y < h; ++y) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
157 for (x = 0; x < w; ++x) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
158 int res; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
159 if (srca[x]) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
160 res = src[x] * (256 - srca[x]); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
161 else |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
162 res = 0; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
163 res = (65535 - res) >> 8; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
164 putc(res&0xff, f); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
165 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
166 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
167 src += stride; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
168 srca += stride; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
169 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
170 putc('\n', f); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
171 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
172 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
173 static void |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
174 draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
175 { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
176 FILE *f; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
177 char buf[128]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
178 char cmd[512]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
179 int cmdres; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
180 const char *const tmpfname = tmpnam(NULL); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
181 sprintf(buf, "subtitle-%d-%d.pgm", spudec->start_pts / 90, spudec->end_pts / 90); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
182 f = fopen(buf, "w"); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
183 output_pgm(f, w, h, src, srca, stride); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
184 fclose(f); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
185 /* see <URL:http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/subtitleripper/subtitleripper/src/README.gocr?rev=HEAD&content-type=text/vnd.viewcvs-markup> */ |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
186 sprintf(cmd, GOCR_PROGRAM" -v 1 -s 7 -d 0 -m 130 -m 256 -m 32 -i %s -o %s", buf, tmpfname); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
187 cmdres = system(cmd); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
188 if (cmdres < 0) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
189 perror("system failed"); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
190 exit(EXIT_FAILURE); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
191 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
192 else if (cmdres) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
193 fprintf(stderr, GOCR_PROGRAM" returned %d\n", cmdres); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
194 exit(cmdres); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
195 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
196 process_gocr_output(tmpfname, spudec->start_pts, spudec->end_pts); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
197 unlink(buf); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
198 unlink(tmpfname); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
199 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
200 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
201 int |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
202 main(int argc, char **argv) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
203 { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
204 const char *vobsubname, *subripname; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
205 void *vobsub; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
206 void *packet; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
207 int packet_len; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
208 unsigned int pts100; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
209 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
210 if (argc < 2 || 4 < argc) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
211 fprintf(stderr, "Usage: %s <vobsub basename> [<subid> [<output filename>] ]\n", argv[0]); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
212 exit(EXIT_FAILURE); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
213 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
214 vobsubname = argv[1]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
215 subripname = NULL; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
216 fsub = stdout; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
217 if (argc >= 3) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
218 vobsub_id = atoi(argv[2]); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
219 if (argc >= 4) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
220 subripname = argv[3]; |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
221 fsub = fopen(subripname, "w"); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
222 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
223 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
224 vobsub = vobsub_open(vobsubname, NULL, 0, &spudec); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
225 while ((packet_len=vobsub_get_next_packet(vobsub, &packet, &pts100)) >= 0) { |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
226 spudec_assemble(spudec, packet, packet_len, pts100); |
10306
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
227 if (spudec->queue_head) { |
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
228 spudec_heartbeat(spudec, spudec->queue_head->start_pts); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28746
diff
changeset
|
229 if (spudec_changed(spudec)) |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
230 spudec_draw(spudec, draw_alpha); |
10306
b7464c68bef3
Fixed: sync structs with spudec.c, implement fast_memcpy
kmkaplan
parents:
6830
diff
changeset
|
231 } |
6830
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
232 } |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
233 |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
234 if (vobsub) |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
235 vobsub_close(vobsub); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
236 exit(EXIT_SUCCESS); |
032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
kmkaplan
parents:
diff
changeset
|
237 } |