Skip to content

Commit

Permalink
Fix scc2srt
Browse files Browse the repository at this point in the history
  • Loading branch information
Szatmary committed Jul 9, 2018
1 parent abf17db commit 3fb17d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
4 changes: 1 addition & 3 deletions examples/scc2srt.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ int main(int argc, char** argv)
utf8_char_t* scc_data_ptr = utf8_load_text_file(argv[1], &scc_size);
utf8_char_t* scc_data = scc_data_ptr;

srt = srt_new();
caption_frame_init(&frame);
scc_data += scc_to_608(&scc, scc_data);

srt = srt_new();

while (scc->cc_size) {
for (i = 0; i < scc->cc_size; ++i) {
// eia608_dump (scc->cc_data[i]);

if (LIBCAPTION_READY == caption_frame_decode(&frame, scc->cc_data[i], scc->timestamp)) {
srt_cue_from_caption_frame(&frame, srt);
}
Expand Down
12 changes: 3 additions & 9 deletions src/scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ size_t scc_to_608(scc_t** scc, const utf8_char_t* data)
}

// Skip blank lines
for (;;) {
llen = utf8_line_length(data);

if (0 == llen || 0 != utf8_trimmed_length(data, llen)) {
break;
}

data += llen;
size += llen;
while(utf8_char_whitespace(data)) {
data += 1, size += 1;
}

if (4 == sscanf(data, "%2d:%2d:%2d%*1[:;]%2d", &hh, &mm, &ss, &ff)) {
Expand All @@ -102,6 +95,7 @@ size_t scc_to_608(scc_t** scc, const utf8_char_t* data)
(*scc)->timestamp = scc_time_to_timestamp(hh, mm, ss, ff);
(*scc)->cc_size = 0;


while ((*scc)->cc_size < max_cc_count && 1 == sscanf(data, "%04x", &cc_data)) {
(*scc)->cc_data[(*scc)->cc_size] = (uint16_t)cc_data;
(*scc)->cc_size += 1;
Expand Down
8 changes: 5 additions & 3 deletions src/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ utf8_size_t utf8_char_count(const char* data, size_t size)
return count;
}

// returnes the length of the line in bytes triming not printable charcters at the end
// returns the length of the line in bytes triming not printable charcters at the end
size_t utf8_trimmed_length(const utf8_char_t* data, utf8_size_t charcters)
{
size_t l, t = 0, split_at = 0;
for (size_t c = 0; (*data) && c < charcters; ++c) {
l = utf8_char_length(data);
t += l, data += l;
if (!utf8_char_whitespace(data)) {
split_at = t;
split_at = t + l;
}
t += l, data += l;
}

return split_at;
Expand All @@ -152,6 +152,8 @@ size_t utf8_line_length(const utf8_char_t* data)
if (0 < (n = _utf8_newline(data))) {
return len + n;
}

data += utf8_char_length(data);
}

return len;
Expand Down

0 comments on commit 3fb17d5

Please sign in to comment.