Commit 315c2c3793987752fd0713d17764ca49aa3275c5
1 parent
e9b85bfd
Exists in
devel
Fix the problem to read empty lines in the field text from SRT subtitle
Showing
3 changed files
with
36 additions
and
11 deletions
Show diff stats
extrator/src/extratorSRT.cpp
| ... | ... | @@ -4,11 +4,15 @@ ExtratorSRT::ExtratorSRT(){ |
| 4 | 4 | listeners = new list<ListenerSub*>(); |
| 5 | 5 | finish = false; |
| 6 | 6 | seek_pos = 0; |
| 7 | + | |
| 8 | + // Used to watch a sequence of the subtitles during the extraction | |
| 9 | + index_counter = 1; | |
| 10 | + | |
| 7 | 11 | hasNextSub = true; |
| 8 | 12 | PRINTL(util::_DEBUG, "ExtratorSTR Done!\n"); |
| 9 | 13 | } |
| 10 | 14 | |
| 11 | -ExtratorSRT::~ExtratorSRT(){ | |
| 15 | +ExtratorSRT::~ExtratorSRT() { | |
| 12 | 16 | listeners->clear(); |
| 13 | 17 | delete listeners; |
| 14 | 18 | if (file_io) delete file_io; |
| ... | ... | @@ -110,14 +114,26 @@ Subtitle* ExtratorSRT::next() { |
| 110 | 114 | string text_sub = ""; |
| 111 | 115 | |
| 112 | 116 | try { |
| 113 | - /* ID */ | |
| 114 | - int id = 0; | |
| 115 | - line = bff_reader->readLine(); | |
| 116 | - seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | |
| 117 | - id = atoi(line.c_str()); | |
| 118 | - sub->setID(id); | |
| 117 | + // ID | |
| 118 | + int id_sub = -1; | |
| 119 | + | |
| 120 | + // Case exists some blank lines before index, read until find | |
| 121 | + do { | |
| 122 | + line = bff_reader->readLine(); | |
| 123 | + printf("%s\n", line.c_str()); | |
| 124 | + seek_pos++; | |
| 125 | + } while (line.size() < 1); | |
| 126 | + | |
| 127 | + //seek_pos += (int64_t) line.size() + SIZE_CSCAPE; | |
| 128 | + id_sub = atoi(line.c_str()); | |
| 129 | + if (id_sub != index_counter) | |
| 130 | + { | |
| 131 | + PRINTL(util::_DEBUG, "[Error] The SRT file is bad formmated: indexes is not continuous.\n"); | |
| 132 | + exit (1); | |
| 133 | + } | |
| 134 | + sub->setID(id_sub); | |
| 119 | 135 | |
| 120 | - /* TimeIn and TimeOut */ | |
| 136 | + // TimeIn and TimeOut | |
| 121 | 137 | int64_t t_in = 0, t_out = 0; |
| 122 | 138 | line = bff_reader->readLine(); |
| 123 | 139 | seek_pos += (int64_t) line.size() + SIZE_CSCAPE; |
| ... | ... | @@ -128,24 +144,32 @@ Subtitle* ExtratorSRT::next() { |
| 128 | 144 | t_out = str_to_time(line.substr(target_pos + strlen(TARGET_TIME)+1, line.size())); |
| 129 | 145 | sub->setTimeOut(t_out); |
| 130 | 146 | |
| 131 | - /* Text: read until line be empty */ | |
| 147 | + // Read until find an empty line | |
| 132 | 148 | while ((line = bff_reader->readLine()).size() > 0) { |
| 133 | 149 | text_sub += line; |
| 134 | 150 | text_sub.append(" "); |
| 135 | 151 | } |
| 152 | + printf("size of text: %d\n", text_sub.size()); | |
| 136 | 153 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
| 137 | 154 | |
| 138 | 155 | } catch (lavidlib::EOFException &ex) { |
| 156 | + | |
| 139 | 157 | if(text_sub == "") |
| 140 | 158 | sub->setTimeIn(0); //seta o valor 0 para nao gerar um valor aleatório |
| 141 | 159 | |
| 142 | 160 | sub->setSubtitleText(formatText(text_sub)); |
| 143 | 161 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
| 162 | + | |
| 144 | 163 | hasNextSub = false; |
| 145 | 164 | delete(bff_reader); |
| 146 | 165 | return sub; |
| 147 | 166 | } |
| 167 | + index_counter++; | |
| 168 | + | |
| 148 | 169 | sub->setSubtitleText(formatText(text_sub)); |
| 170 | + | |
| 171 | + printf("%s\n\n", sub->toString().c_str()); | |
| 172 | + | |
| 149 | 173 | delete(bff_reader); |
| 150 | 174 | return sub; |
| 151 | 175 | } | ... | ... |
extrator/src/include/extratorSRT.h
recognize/src/recognizer.cpp