[MPlayer-dev-eng] [PATCH] Matroska, options -aid and -sid

Bruno Lecointre bruno-lecointre at pacbell.net
Mon Aug 25 10:29:37 CEST 2003


Hi,
for the Matroska file format, the comand line options -aid and -sid will
assume that the value given is the id of the track in the file played.
This means that one has to try a couple of times before finding the
correct settings. Also, in case the user provides an incorrect audio
track, no warning is displayed and there is no audio. In case of the
subtitles, you will get a warning, for example:
Subtitle type 'A_VORBIS' is not supported.
which is helpful only if you understand the Matroska format.
Unfortunately, this is also due to the nature of the Matroska format
since they want to support pretty much anything.

The patch renames the current implementation of find_track_by_num to
find_duplicate_track_by_num since it is one of its use, and implements
find_track_by_num so that it returns the nth track of type track_type
found,starting from zero, or null if none is found.
I find it a little easier to use the command line with the patch.

Bruno
-------------- next part --------------
--- demux_mkv.cpp	2003-08-25 00:51:33.000000000 -0700
+++ demux_mkv.cpp.new	2003-08-25 01:03:08.000000000 -0700
@@ -452,7 +452,22 @@
 }
 
 static mkv_track_t *find_track_by_num(mkv_demuxer_t *d, uint32_t n,
-                                      mkv_track_t *c) {
+                                      char track_type) {
+  int i, track_type_count = 0;
+
+  for (i = 0; i < d->num_tracks; i++)
+    if ((d->tracks[i] != NULL) && (d->tracks[i]->type == track_type)) {
+      if (track_type_count == n)
+        return d->tracks[i];
+      else
+        track_type_count++;
+    }
+  
+  return NULL;
+}
+
+static mkv_track_t *find_duplicate_track_by_num(mkv_demuxer_t *d, uint32_t n,
+                                                mkv_track_t *c) {
   int i;
   
   for (i = 0; i < d->num_tracks; i++)
@@ -1164,7 +1179,7 @@
             mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |  + Track number: %u\n",
                    uint32(*ktnum));
             track->tnum = uint32(*ktnum);
-            if (find_track_by_num(mkv_d, track->tnum, track) != NULL)
+            if (find_duplicate_track_by_num(mkv_d, track->tnum, track) != NULL)
               mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] |  + WARNING: There's "
                      "more than one track with the number %u.\n",
                      track->tnum);
@@ -1434,7 +1449,7 @@
           break;
         }
   } else if (demuxer->video->id != -2) // -2 = no video at all
-    track = find_track_by_num(mkv_d, demuxer->video->id, NULL);
+    track = find_track_by_num(mkv_d, demuxer->video->id, 'v');
 
   if (track) {
     BITMAPINFOHEADER *bih;
@@ -1565,7 +1580,7 @@
           break;
         }
   } else if (demuxer->audio->id != -2) // -2 = no audio at all
-    track = find_track_by_num(mkv_d, demuxer->audio->id, NULL);
+    track = find_track_by_num(mkv_d, demuxer->audio->id, 'a');
 
   if (track) {
     mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will play audio track %u\n",
@@ -1725,7 +1740,7 @@
   // playback: only show subtitles if the user explicitely wants them.
   track = NULL;
   if (demuxer->sub->id >= 0)
-    track = find_track_by_num(mkv_d, demuxer->sub->id, NULL);
+    track = find_track_by_num(mkv_d, demuxer->sub->id, 's');
   else if (dvdsub_lang != NULL)
     track = find_track_by_language(mkv_d, dvdsub_lang, NULL);
   if (track) {


More information about the MPlayer-dev-eng mailing list