Skip to content

Commit

Permalink
Add support for default of multiple video tracks.
Browse files Browse the repository at this point in the history
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.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@36778 b3059339-0415-0410-9bf9-f77b7e298cf2
  • Loading branch information
ib committed Feb 2, 2014
1 parent 1e0e0cb commit 1e1f020
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libmpdemux/demux_lavf.c
Expand Up @@ -403,6 +403,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
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",
Expand Down
16 changes: 16 additions & 0 deletions libmpdemux/demuxer.c
Expand Up @@ -1916,6 +1916,22 @@ int demuxer_default_audio_track(demuxer_t *d)
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;
Expand Down
1 change: 1 addition & 0 deletions libmpdemux/demuxer.h
Expand Up @@ -486,6 +486,7 @@ int demuxer_sub_track_by_lang(demuxer_t* demuxer, char* lang);
// 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 */
4 changes: 2 additions & 2 deletions mencoder.c
Expand Up @@ -709,10 +709,10 @@ if(stream->type==STREAMTYPE_DVDNAV){
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)
Expand Down
10 changes: 10 additions & 0 deletions mpcommon.c
Expand Up @@ -416,6 +416,16 @@ int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang)
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;
Expand Down
1 change: 1 addition & 0 deletions mpcommon.h
Expand Up @@ -75,6 +75,7 @@ void init_vo_spudec(struct stream *stream, struct sh_video *sh_video, struct sh_
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);
Expand Down
4 changes: 4 additions & 0 deletions mplayer.c
Expand Up @@ -3458,6 +3458,10 @@ int main(int argc, char *argv[])
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);

Expand Down

0 comments on commit 1e1f020

Please sign in to comment.