# HG changeset patch # User reimar # Date 1253742528 0 # Node ID 2e3751815a2165a345a581e4e4305f79817d17a1 # Parent 162402f4662ba12dd15439798e3a01d25a58aee9 Add support for displaying subtitles on the command-line when playing audio-only files. diff -r 162402f4662b -r 2e3751815a21 mencoder.c --- 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 diff -r 162402f4662b -r 2e3751815a21 mp_osd.h --- 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 diff -r 162402f4662b -r 2e3751815a21 mpcommon.c --- 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; } diff -r 162402f4662b -r 2e3751815a21 mpcommon.h --- 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; diff -r 162402f4662b -r 2e3751815a21 mplayer.c --- 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 {