[MPlayer-dev-eng] [PATCH] Make all subtitles availiable

Sturle Sunde sturle.sunde at usit.uio.no
Wed Nov 29 15:47:00 CET 2006


Some DVDs have gaps in the subtitle tracks, like this one:

  subtitle ( sid ): 0 language: da
  ID_SUBTITLE_ID=1
  ID_SID_0_LANG=da
  subtitle ( sid ): 1 language: sv
  ID_SUBTITLE_ID=3
  ID_SID_1_LANG=sv
  subtitle ( sid ): 2 language: no
  ID_SUBTITLE_ID=5
  ID_SID_2_LANG=no
  subtitle ( sid ): 3 language: fi
  ID_SUBTITLE_ID=7
  ID_SID_3_LANG=fi
  number of subtitles on disk: 4
  CHAPTERS: 00:00:00,00:00:55,00:02:34,00:07:51,00:12:29,00:14:50,00:22:05,00:28:35,00:33:39,00:42:17,00:45:19,00:52:10,00:57:57,01:03:56,01:07:47,01:14:22,01:19:50,01:23:26,01:28:57,
  Selected DVD subtitle channel: 2 language: no

When i play this DVD with -slang no, i get swedish subtitles because
it plays subtitle ID 2, not 5.  (No 2 is valid, see below.)  I guess
this is the same bug that Mogens Kjær reported to MPlayer-users at
July 21.  I can choose between Danish and Swedish subtitles with the
-sid option, or by cycling, but Norwegian and Finnish are unavailiable
because the IDs are above the detected number of subtitles.

Here is a simple patch to make all detected subtitle IDs availiable,
even when there are gaps in the numbering.  It changes the numbering
and IDs to be more similar to the method used by audio tracks.

Btw: The subtitle tracks in between show up as debugging output when i
play the DVD, just after the actual playback has started, but are
still unavailiable on an unpatched version.  Like this:

  ID_SUBTITLE_ID=24 A-V:  0.016 ct:  0.038  29/ 29 68% 17% 22.8% 7 0 
  ID_SUBTITLE_ID=3
  ID_SUBTITLE_ID=0
  ID_SUBTITLE_ID=1
  ID_SUBTITLE_ID=4
  ID_SUBTITLE_ID=5
  ID_SUBTITLE_ID=6
  ID_SUBTITLE_ID=7

Patch follows:


Index: stream/stream_dvd.c
===================================================================
--- stream/stream_dvd.c (revision 21386)
+++ stream/stream_dvd.c (working copy)
@@ -180,16 +180,20 @@
   if (!stream) return -1;
   d = stream->priv;
   if (!d) return -1;
-  return d->nr_of_subtitles;
+  return d->subtitles[d->nr_of_subtitles].id;
 }
 
 int dvd_lang_from_sid(stream_t *stream, int id) {
+  int i;
   dvd_priv_t *d;
   if (!stream) return 0;
   d = stream->priv;
   if (!d) return 0;
-  if (id >= d->nr_of_subtitles) return 0;
-  return d->subtitles[id].language;
+  for(i=0;i<d->nr_of_subtitles;i++) {
+    if(d->subtitles[i].id==id)
+      return d->subtitles[i].language;
+  }
+  return 0;
 }
 
 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang) {
@@ -199,8 +203,9 @@
     code=lang[1]|(lang[0]<<8);
     for(i=0;i<d->nr_of_subtitles;i++) {
       if(d->subtitles[i].language==code) {
-        mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDsubtitleChannel, i, lang[0],lang[1]);
-        return i;
+        mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDsubtitleChannel, 
+       d->subtitles[i].id, lang[0],lang[1]);
+        return d->subtitles[i].id;
       }
     }
     lang+=2; 
@@ -974,10 +979,10 @@
           d->subtitles[d->nr_of_subtitles].id = vts_file->vts_pgcit->pgci_srp[ttn].pgc->subp_control[i] >> 8 & 31;
 #endif
 
-        mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDsubtitleLanguage, d->nr_of_subtitles, tmp);
+        mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDsubtitleLanguage, d->subtitles[d->nr_of_subtitles].id, tmp);
         mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", d->subtitles[d->nr_of_subtitles].id);
         if(language && tmp[0])
-          mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", d->nr_of_subtitles, tmp);
+          mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", d->subtitles[d->nr_of_subtitles].id, tmp);
         d->nr_of_subtitles++;
       }
       mp_msg(MSGT_OPEN,MSGL_STATUS,MSGTR_DVDnumSubtitles,d->nr_of_subtitles);


-- 
Sturle
~~~~~~



More information about the MPlayer-dev-eng mailing list