changeset 36682:68794f2fbf1e

Add support for default of multiple video tracks. Some container formats like matroska support multiple video tracks, one of which may be flagged the 'default' one which thus should be played by default. Works with the lavf demuxer.
author ib
date Sun, 02 Feb 2014 19:18:31 +0000
parents c3962450b00b
children acb4a92aba16
files libmpdemux/demux_lavf.c libmpdemux/demuxer.c libmpdemux/demuxer.h mencoder.c mpcommon.c mpcommon.h mplayer.c
diffstat 7 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_lavf.c	Sun Feb 02 10:54:37 2014 +0000
+++ b/libmpdemux/demux_lavf.c	Sun Feb 02 19:18:31 2014 +0000
@@ -403,6 +403,8 @@
             sh_video->i_bps=codec->bit_rate/8;
             if (title && title->value)
                 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n", priv->video_streams, title->value);
+            if (st->disposition & AV_DISPOSITION_DEFAULT)
+                sh_video->default_track = 1;
             if (rot && rot->value)
                 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_ROTATE=%s\n", priv->video_streams, rot->value);
             mp_msg(MSGT_DEMUX,MSGL_DBG2,"aspect= %d*%d/(%d*%d)\n",
--- a/libmpdemux/demuxer.c	Sun Feb 02 10:54:37 2014 +0000
+++ b/libmpdemux/demuxer.c	Sun Feb 02 19:18:31 2014 +0000
@@ -1916,6 +1916,22 @@
     return -1;
 }
 
+int demuxer_default_video_track(demuxer_t *d)
+{
+    int i;
+    for (i = 0; i < MAX_V_STREAMS; ++i) {
+        sh_video_t *sh = d->v_streams[i];
+        if (sh && sh->default_track)
+            return sh->vid;
+    }
+    for (i = 0; i < MAX_V_STREAMS; ++i) {
+        sh_video_t *sh = d->v_streams[i];
+        if (sh)
+            return sh->vid;
+    }
+    return -1;
+}
+
 int demuxer_default_sub_track(demuxer_t *d)
 {
     int i;
--- a/libmpdemux/demuxer.h	Sun Feb 02 10:54:37 2014 +0000
+++ b/libmpdemux/demuxer.h	Sun Feb 02 19:18:31 2014 +0000
@@ -486,6 +486,7 @@
 // for subtitles, it is the first track with default attribute
 // for audio, additionally, the first track is selected if no track has default attribute set
 int demuxer_default_audio_track(demuxer_t* d);
+int demuxer_default_video_track(demuxer_t* d);
 int demuxer_default_sub_track(demuxer_t* d);
 
 #endif /* MPLAYER_DEMUXER_H */
--- a/mencoder.c	Sun Feb 02 10:54:37 2014 +0000
+++ b/mencoder.c	Sun Feb 02 19:18:31 2014 +0000
@@ -709,10 +709,10 @@
     demux_program_t prog = { .progid = ts_prog };
     if (demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) != DEMUXER_CTRL_NOTIMPL) {
       audio_id = prog.aid; // switching is handled by select_audio below
-      video_id = prog.vid;
-      demuxer_switch_video(demuxer, video_id);
+      video_id = prog.vid; // switching is handled by select_video below
     }
   }
+  select_video(demuxer, video_id);
   select_audio(demuxer, audio_id, audio_lang);
 
   if (dvdsub_id == -1 && dvdsub_lang)
--- a/mpcommon.c	Sun Feb 02 10:54:37 2014 +0000
+++ b/mpcommon.c	Sun Feb 02 19:18:31 2014 +0000
@@ -416,6 +416,16 @@
     return demuxer->audio->id;
 }
 
+int select_video(demuxer_t* demuxer, int video_id)
+{
+    if (video_id == -1)
+        video_id = demuxer_default_video_track(demuxer);
+    if (video_id != -1) // -1 (automatic) is the default behaviour of demuxers
+        demuxer_switch_video(demuxer, video_id);
+
+    return demuxer->video->id;
+}
+
 /* Parse -noconfig common to both programs */
 int disable_system_conf=0;
 int disable_user_conf=0;
--- a/mpcommon.h	Sun Feb 02 10:54:37 2014 +0000
+++ b/mpcommon.h	Sun Feb 02 19:18:31 2014 +0000
@@ -75,6 +75,7 @@
 void update_subtitles(struct sh_video *sh_video, double refpts, demux_stream_t *d_dvdsub, int reset);
 void update_teletext(struct sh_video *sh_video, demuxer_t *demuxer, int reset);
 int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
+int select_video(demuxer_t* demuxer, int video_id);
 void set_osd_subtitle(subtitle *subs);
 
 int cfg_inc_verbose(m_option_t *conf);
--- a/mplayer.c	Sun Feb 02 10:54:37 2014 +0000
+++ b/mplayer.c	Sun Feb 02 19:18:31 2014 +0000
@@ -3458,6 +3458,10 @@
         int tmp = ts_prog;
         mp_property_do("switch_program", M_PROPERTY_SET, &tmp, mpctx);
     }
+
+    // select video stream
+    select_video(mpctx->demuxer, video_id);
+
     // select audio stream
     select_audio(mpctx->demuxer, audio_id, audio_lang);