Mercurial > mplayer.hg
changeset 29670:2e3751815a21
Add support for displaying subtitles on the command-line when playing
audio-only files.
author | reimar |
---|---|
date | Wed, 23 Sep 2009 21:48:48 +0000 |
parents | 162402f4662b |
children | 3f5e7b22b2a6 |
files | mencoder.c mp_osd.h mpcommon.c mpcommon.h mplayer.c |
diffstat | 5 files changed, 34 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mencoder.c Wed Sep 23 21:27:36 2009 +0000 +++ b/mencoder.c Wed Sep 23 21:48:48 2009 +0000 @@ -218,6 +218,12 @@ char *current_module; #include "mpcommon.h" +// Needed by mpcommon.c +void set_osd_subtitle(subtitle *subs) { + vo_sub = subs; + vo_osd_changed(OSDTYPE_SUBTITLE); +} + //char *out_audio_codec=NULL; // override audio codec //char *out_video_codec=NULL; // override video codec
--- a/mp_osd.h Wed Sep 23 21:27:36 2009 +0000 +++ b/mp_osd.h Wed Sep 23 21:48:48 2009 +0000 @@ -11,6 +11,7 @@ #define OSD_MSG_RADIO_CHANNEL 7 /// Base id for messages generated from the commmand to property bridge. #define OSD_MSG_PROPERTY 0x100 +#define OSD_MSG_SUB_BASE 0x1000 #define MAX_OSD_LEVEL 3 #define MAX_TERM_OSD_LEVEL 1
--- a/mpcommon.c Wed Sep 23 21:27:36 2009 +0000 +++ b/mpcommon.c Wed Sep 23 21:48:48 2009 +0000 @@ -75,8 +75,7 @@ if (reset) { sub_clear_text(&subs, MP_NOPTS_VALUE); if (vo_sub) { - vo_sub = NULL; - vo_osd_changed(OSDTYPE_SUBTITLE); + set_osd_subtitle(NULL); } if (vo_spudec) { spudec_reset(vo_spudec); @@ -145,7 +144,6 @@ } else if (dvdsub_id >= 0 && (type == 't' || type == 'm' || type == 'a')) { double curpts = refpts + sub_delay; double endpts; - vo_sub = &subs; while (d_dvdsub->first) { double subpts = ds_get_next_pts(d_dvdsub); if (subpts > curpts) @@ -167,7 +165,6 @@ (long long)(subpts*1000 + 0.5), (long long)((endpts-subpts)*1000 + 0.5)); } else { // plaintext subs with libass - vo_sub = NULL; if (subpts != MP_NOPTS_VALUE) { if (endpts == MP_NOPTS_VALUE) endpts = subpts + 3; sub_clear_text(&subs, MP_NOPTS_VALUE); @@ -195,11 +192,11 @@ packet = p; } sub_add_text(&subs, packet, len, endpts); - vo_osd_changed(OSDTYPE_SUBTITLE); + set_osd_subtitle(&subs); } } if (sub_clear_text(&subs, curpts)) - vo_osd_changed(OSDTYPE_SUBTITLE); + set_osd_subtitle(&subs); } current_module=NULL; }
--- a/mpcommon.h Wed Sep 23 21:27:36 2009 +0000 +++ b/mpcommon.h Wed Sep 23 21:48:48 2009 +0000 @@ -13,6 +13,7 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvdsub, int reset); void update_teletext(sh_video_t *sh_video, demuxer_t *demuxer, int reset); int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang); +void set_osd_subtitle(subtitle *subs); extern int disable_system_conf; extern int disable_user_conf;
--- a/mplayer.c Wed Sep 23 21:27:36 2009 +0000 +++ b/mplayer.c Wed Sep 23 21:48:48 2009 +0000 @@ -1507,6 +1507,26 @@ name,ROUND(100*(val-min)/(max-min))); } +/** + * \brief Display text subtitles on the OSD + */ +void set_osd_subtitle(subtitle *subs) { + int i; + vo_sub = subs; + vo_osd_changed(OSDTYPE_SUBTITLE); + if (!mpctx->sh_video) { + // reverse order, since newest set_osd_msg is displayed first + for (i = SUB_MAX_TEXT - 1; i >= 0; i--) { + if (!subs || i >= subs->lines || !subs->text[i]) + rm_osd_msg(OSD_MSG_SUB_BASE + i); + else { + // HACK: currently display time for each sub line except the last is set to 2 seconds. + int display_time = i == subs->lines - 1 ? 180000 : 2000; + set_osd_msg(OSD_MSG_SUB_BASE + i, 1, display_time, "%s", subs->text[i]); + } + } + } +} /** * \brief Update the OSD message line. @@ -2492,6 +2512,8 @@ mpctx->audio_out->reset(); // stop audio, throwing away buffered data mpctx->sh_audio->a_buffer_len = 0; mpctx->sh_audio->a_out_buffer_len = 0; + if (!mpctx->sh_video) + update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 1); } if (vo_vobsub && mpctx->sh_video) { @@ -3704,6 +3726,7 @@ if(end_at.type == END_AT_TIME && end_at.pos < a_pos) mpctx->eof = PT_NEXT_ENTRY; + update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 0); update_osd_msg(); } else {