Esempio n. 1
0
int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context)
{
	int ret = 0;
#ifdef ENABLE_OCR
	struct cc_bitmap* rect;
	LLONG ms_start, ms_end;
	unsigned h1,m1,s1,ms1;
	unsigned h2,m2,s2,ms2;
	char timeline[128];
	int len = 0;
	int used;
	int i = 0;
	char *str;

	ms_start = sub->start_time + context->subs_delay;
	ms_end = sub->end_time + context->subs_delay;

    if (ms_start<0) // Drop screens that because of subs_delay start too early
        return 0;

	if(sub->nb_data == 0 )
		return 0;

	if(sub->flags & SUB_EOD_MARKER)
		context->prev_start =  sub->start_time;

	str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length);
	if (str)
	{
		if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER))
		{
			millis_to_time (ms_start,&h1,&m1,&s1,&ms1);
			millis_to_time (ms_end-1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line.
			context->srt_counter++;
			sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf);
			used = encode_line(context, context->buffer,(unsigned char *) timeline);
			write(context->out->fh, context->buffer, used);
			sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u%s",
				h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
			used = encode_line(context, context->buffer,(unsigned char *) timeline);
            write (context->out->fh, context->buffer, used);
			len = strlen(str);
            write (context->out->fh, str, len);
			write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
		}
		freep(&str);
	}
	for(i = 0, rect = sub->data; i < sub->nb_data; i++, rect++)
	{
		freep(rect->data);
		freep(rect->data+1);
	}
#endif
	sub->nb_data = 0;
	freep(&sub->data);
	return ret;

}
int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *context)
{
	int ret = 0;
#ifdef ENABLE_OCR
	struct cc_bitmap* rect;

	unsigned h1, m1, s1, ms1;

	LLONG start_time, end_time;

	if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER))
	{
		start_time = context->prev_start + context->subs_delay;
		end_time = sub->start_time - 1;
	}
	else if (!(sub->flags & SUB_EOD_MARKER))
	{
		start_time = sub->start_time + context->subs_delay;
		end_time = sub->end_time - 1;
	}

	if (sub->nb_data == 0)
		return ret;
	rect = sub->data;

	if (sub->flags & SUB_EOD_MARKER)
		context->prev_start = sub->start_time;


	if (rect[0].ocr_text && *(rect[0].ocr_text))
	{
		if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER))
		{
			char *token = NULL;
			token = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length);
			if (context->transcript_settings->showStartTime)
			{
				char buf1[80];
				if (context->transcript_settings->relativeTimestamp)
				{
					millis_to_date(start_time + context->subs_delay, buf1, context->date_format, context->millis_separator);
					fdprintf(context->out->fh, "%s|", buf1);
				}
				else
				{
					mstotime(start_time + context->subs_delay, &h1, &m1, &s1, &ms1);
					time_t start_time_int = (start_time + context->subs_delay) / 1000;
					int start_time_dec = (start_time + context->subs_delay) % 1000;
					struct tm *start_time_struct = gmtime(&start_time_int);
					strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct);
					fdprintf(context->out->fh, "%s%c%03d|", buf1, context->millis_separator, start_time_dec);
				}
			}

			if (context->transcript_settings->showEndTime)
			{
				char buf2[80];
				if (context->transcript_settings->relativeTimestamp)
				{
					millis_to_date(end_time, buf2, context->date_format, context->millis_separator);
					fdprintf(context->out->fh, "%s|", buf2);
				}
				else
				{
					time_t end_time_int = end_time / 1000;
					int end_time_dec = end_time % 1000;
					struct tm *end_time_struct = gmtime(&end_time_int);
					strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct);
					fdprintf(context->out->fh, "%s%c%03d|", buf2, context->millis_separator, end_time_dec);
				}
			}
			if (context->transcript_settings->showCC)
			{
				fdprintf(context->out->fh, "%s|", language[sub->lang_index]);
			}
			if (context->transcript_settings->showMode)
			{
				fdprintf(context->out->fh, "DVB|");
			}

			while (token)
			{
				char *newline_pos = strstr(token, context->encoded_crlf);
				if (!newline_pos)
				{
					fdprintf(context->out->fh, "%s", token);
					break;
				}
				else
				{
					while (token != newline_pos)
					{
						fdprintf(context->out->fh, "%c", *token);
						token++;
					}
					token += context->encoded_crlf_length;
					fdprintf(context->out->fh, "%c", ' ');
				}
			}

			write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);

		}
	}
#endif

	sub->nb_data = 0;
	freep(&sub->data);
	return ret;

}
Esempio n. 3
0
int write_cc_bitmap_as_libcurl(struct cc_subtitle *sub, struct encoder_ctx *context)
{
	int ret = 0;
#ifdef ENABLE_OCR
	struct cc_bitmap* rect;
	LLONG ms_start, ms_end;
	unsigned h1, m1, s1, ms1;
	unsigned h2, m2, s2, ms2;
	char timeline[128];
	int len = 0;
	int used;
	int i = 0;
	char *str;

	if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER))
	{
		ms_start = context->prev_start;
		ms_end = sub->start_time;
	}
	else if (!(sub->flags & SUB_EOD_MARKER))
	{
		ms_start = sub->start_time;
		ms_end = sub->end_time;
	}
	else if (context->prev_start == -1 && (sub->flags & SUB_EOD_MARKER))
	{
		ms_start = 1;
		ms_end = sub->start_time;
	}

	if (sub->nb_data == 0)
		return 0;

	if (sub->flags & SUB_EOD_MARKER)
		context->prev_start = sub->start_time;

	str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length);
	if (str)
	{
		if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER))
		{
			millis_to_time(ms_start, &h1, &m1, &s1, &ms1);
			millis_to_time(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line.
			context->srt_counter++;
			sprintf(timeline, "group_id=ccextractordev&start_time=%" PRIu64 "&end_time=%" PRIu64 "&lang=en", ms_start, ms_end);
			char *curlline = NULL;
			curlline = str_reallocncat(curlline, timeline);
			curlline = str_reallocncat(curlline, "&payload=");
			char *urlencoded=curl_easy_escape (curl, str, 0);
			curlline = str_reallocncat(curlline,urlencoded);
			curl_free (urlencoded);
			mprint("%s", curlline);

			char *result = malloc(strlen(ccx_options.curlposturl) + strlen("/frame/") + 1);
			strcpy(result, ccx_options.curlposturl);
			strcat(result, "/frame/");
			curl_easy_setopt(curl, CURLOPT_URL, result);
			curl_easy_setopt(curl, CURLOPT_POSTFIELDS, curlline);
			free(result);

			res = curl_easy_perform(curl);
			/* Check for errors */
			if(res != CURLE_OK)
				mprint("curl_easy_perform() failed: %s\n",
				curl_easy_strerror(res));
		}
		freep(&str);
	}
	for (i = 0, rect = sub->data; i < sub->nb_data; i++, rect++)
	{
		freep(rect->data);
		freep(rect->data + 1);
	}
#endif
	sub->nb_data = 0;
	freep(&sub->data);
	return ret;

}