[MPlayer-dev-eng] Subtitle timing correction
Adam Tlałka
atlka at pg.gda.pl
Sat May 13 10:31:35 CEST 2006
Welcome,
I found that subreader.c:adjust_subs_time() works incorrectly in some cases.
It should check if sub_uses_time is set and then calculate time
of single frame to correct overlapping subtitles timings.
Patch attached.
Regards
--
Adam Tlałka mailto:atlka at pg.gda.pl ^v^ ^v^ ^v^
PGP public key: finger atlka at sunrise.pg.gda.pl
-------------- next part --------------
--- ../main_dist/subreader.c 2006-05-13 07:52:53.000000000 +0200
+++ subreader.c 2006-05-13 08:07:04.000000000 +0200
@@ -1241,39 +1241,42 @@
static void adjust_subs_time(subtitle* sub, float subtime, float fps, int block,
int sub_num, int sub_uses_time) {
- int n,m;
+ int i,j,n,m;
subtitle* nextsub;
- int i = sub_num;
unsigned long subfms = (sub_uses_time ? 100 : fps) * subtime;
+ unsigned long substep = (sub_uses_time ? 100 / fps + 1 : 1); // ~1 frame
unsigned long overlap = (sub_uses_time ? 100 : fps) / 5; // 0.2s
n=m=0;
+ i=j=sub_num;
if (i) for (;;){
if (sub->end <= sub->start){
sub->end = sub->start + subfms;
m++;
n++;
+ mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: %d: end time corrected .\n",j-i+1);
}
if (!--i) break;
nextsub = sub + 1;
- if(block){
- if ((sub->end > nextsub->start) && (sub->end <= nextsub->start + overlap)) {
- // these subtitles overlap for less than 0.2 seconds
- // and would result in very short overlapping subtitle
- // so let's fix the problem here, before overlapping code
- // get its hands on them
- unsigned delta = sub->end - nextsub->start, half = delta / 2;
- sub->end -= half + 1;
- nextsub->start += delta - half;
- }
if (sub->end >= nextsub->start){
- sub->end = nextsub->start - 1;
- if (sub->end - sub->start > subfms)
- sub->end = sub->start + subfms;
- if (!m)
- n++;
- }
- }
+ if (block){
+ sub->end = nextsub->start - substep;
+ if (sub->end - sub->start > subfms)
+ sub->end = sub->start + subfms;
+ if (!m)
+ n++;
+ mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: %d: overlapping removed.\n",j-i);
+ } else if (sub->end <= nextsub->start + overlap){
+ // these subtitles overlap for less than 0.2 seconds
+ // and would result in very short overlapping subtitle
+ // so let's fix the problem here, before overlapping code
+ // get its hands on them
+ sub->end = nextsub->start + overlap + substep;
+ if (!m)
+ n++;
+ mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: %d: overlapping corrected.\n",j-i);
+ }
+ }
/* Theory:
* Movies are often converted from FILM (24 fps)
@@ -1508,7 +1511,7 @@
return NULL;
}
- // we do overlap if the user forced it (suboverlap_enable == 2) or
+ // we do overlap if the user forced it (suboverlap_enabled == 2) or
// the user didn't forced no-overlapsub and the format is Jacosub or Ssa.
// this is because usually overlapping subtitles are found in these formats,
// while in others they are probably result of bad timing
@@ -1715,7 +1718,7 @@
free(first);
return_sub = second;
-} else { //if(suboverlap_enabled)
+} else { // we do not overlap subtitles
adjust_subs_time(first, 6.0, fps, 1, sub_num, uses_time);/*~6 secs AST*/
return_sub = first;
}
More information about the MPlayer-dev-eng
mailing list