Commit 302ca689 authored by oggk's avatar oggk
Browse files

support display coordinates in SRT input; OK'd by j.

parent 7a9d875d
......@@ -1693,7 +1693,7 @@ void ff2theora_output(ff2theora this) {
while (ks->subtitles_count < ks->num_subtitles && sub->t0-1.0 <= avtime+this->start_time) {
#ifdef HAVE_KATE
if (sub->text) {
oggmux_add_kate_text(&info, i, sub->t0, sub->t1, sub->text, sub->len);
oggmux_add_kate_text(&info, i, sub->t0, sub->t1, sub->text, sub->len, sub->x1, sub->x2, sub->y1, sub->y2);
}
else {
oggmux_add_kate_image(&info, i, sub->t0, sub->t1, &sub->kr, &sub->kp, &sub->kb);
......
......@@ -13,6 +13,7 @@ typedef struct ff2theora_subtitle{
kate_palette kp;
kate_bitmap kb;
#endif
int x1,x2,y1,y2;
} ff2theora_subtitle;
typedef struct ff2theora_kate_stream{
......
......@@ -343,6 +343,7 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8, FILE *front
int id;
static char text[4096];
int h0,m0,s0,ms0,h1,m1,s1,ms1;
int x1,x2,y1,y2;
double t0=0.0;
double t1=0.0;
static char str[4096];
......@@ -397,17 +398,25 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8, FILE *front
}
break;
case need_timing:
ret=sscanf(str,"%d:%d:%d%*[.,]%d --> %d:%d:%d%*[.,]%d\n",&h0,&m0,&s0,&ms0,&h1,&m1,&s1,&ms1);
if (ret!=8 || (h0|m0|s0|ms0)<0 || (h1|m1|s1|ms1)<0) {
warn(frontend, this->filename, line, "Syntax error: %s",str);
ret=sscanf(str,"%d:%d:%d%*[.,]%d --> %d:%d:%d%*[.,]%d %*[xX]1: %d %*[xX]2: %d %*[yY]1: %d %*[yY]2: %d\n",&h0,&m0,&s0,&ms0,&h1,&m1,&s1,&ms1,&x1,&x2,&y1,&y2);
if (ret!=12) {
x1=y1=x2=y2=-INT_MAX;
ret=sscanf(str,"%d:%d:%d%*[.,]%d --> %d:%d:%d%*[.,]%d\n",&h0,&m0,&s0,&ms0,&h1,&m1,&s1,&ms1);
if (ret!=8) {
warn(frontend, this->filename, line, "Syntax error: %s",str);
fclose(f);
free(this->subtitles);
return -1;
}
}
t0=hmsms2s(h0,m0,s0,ms0);
t1=hmsms2s(h1,m1,s1,ms1);
if ((h0|m0|s0|ms0)<0 || (h1|m1|s1|ms1)<0) {
warn(frontend, this->filename, line, "Bad timestamp specification: %s",str);
fclose(f);
free(this->subtitles);
return -1;
}
else {
t0=hmsms2s(h0,m0,s0,ms0);
t1=hmsms2s(h1,m1,s1,ms1);
}
need=need_text;
break;
case need_text:
......@@ -452,6 +461,10 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8, FILE *front
this->subtitles[this->num_subtitles].len = len;
this->subtitles[this->num_subtitles].t0 = t0;
this->subtitles[this->num_subtitles].t1 = t1;
this->subtitles[this->num_subtitles].x1 = x1;
this->subtitles[this->num_subtitles].x2 = x2;
this->subtitles[this->num_subtitles].y1 = y1;
this->subtitles[this->num_subtitles].y2 = y2;
this->num_subtitles++;
}
need=need_id;
......@@ -522,6 +535,10 @@ int add_subtitle_for_stream(ff2theora_kate_stream *streams, int nstreams, int id
ks->subtitles[ks->num_subtitles].len = utf8len;
ks->subtitles[ks->num_subtitles].t0 = t;
ks->subtitles[ks->num_subtitles].t1 = t+duration;
ks->subtitles[ks->num_subtitles].x1 = -INT_MAX;
ks->subtitles[ks->num_subtitles].x2 = -INT_MAX;
ks->subtitles[ks->num_subtitles].y1 = -INT_MAX;
ks->subtitles[ks->num_subtitles].y2 = -INT_MAX;
ks->num_subtitles++;
}
}
......
......@@ -1319,10 +1319,24 @@ static void oggmux_record_kate_index(oggmux_info *info, oggmux_kate_stream *ks,
* @param text the utf-8 text
* @param len the number of bytes in the text
*/
void oggmux_add_kate_text (oggmux_info *info, int idx, double t0, double t1, const char *text, size_t len) {
void oggmux_add_kate_text (oggmux_info *info, int idx, double t0, double t1, const char *text, size_t len, int x1, int x2, int y1, int y2) {
ogg_packet op;
oggmux_kate_stream *ks=info->kate_streams+idx;
int ret;
if (x1!=-INT_MAX && y1!=-INT_MAX && x2!=-INT_MAX && y2!=-INT_MAX) {
kate_region kr;
kate_region_init(&kr);
kr.metric=kate_pixel;
kr.x=x1;
kr.y=y1;
kr.w=x2-x1+1;
kr.h=y2-y1+1;
ret=kate_encode_set_region(&ks->k,&kr);
if (ret<0) {
fprintf(stderr,"Error setting region: %d\n",ret);
return;
}
}
ret = kate_ogg_encode_text(&ks->k, t0, t1, text, len, &op);
if (ret>=0) {
if (!info->skeleton_3 && info->passno != 1) {
......
......@@ -168,7 +168,7 @@ extern void oggmux_init (oggmux_info *info);
extern void oggmux_add_video (oggmux_info *info, th_ycbcr_buffer ycbcr, int e_o_s);
extern void oggmux_add_audio (oggmux_info *info, int16_t * readbuffer, int bytesread, int samplesread,int e_o_s);
#ifdef HAVE_KATE
extern void oggmux_add_kate_text (oggmux_info *info, int idx, double t0, double t1, const char *text, size_t len);
extern void oggmux_add_kate_text (oggmux_info *info, int idx, double t0, double t1, const char *text, size_t len, int x1, int x2, int y1, int y2);
extern void oggmux_add_kate_image (oggmux_info *info, int idx, double t0, double t1, const kate_region *kr, const kate_palette *kp, const kate_bitmap *kb);
extern void oggmux_add_kate_end_packet (oggmux_info *info, int idx, double t);
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment