mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
Add support for displaying subtitles on the command-line when playing
audio-only files. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29712 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
1b92715364
commit
4b182ff652
@ -218,6 +218,12 @@ void mplayer_put_key(int code)
|
||||
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
|
||||
|
||||
|
1
mp_osd.h
1
mp_osd.h
@ -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
|
||||
|
@ -75,8 +75,7 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
|
||||
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 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
|
||||
} 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 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
|
||||
(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 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
|
||||
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;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ void print_version(const char* name);
|
||||
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;
|
||||
|
23
mplayer.c
23
mplayer.c
@ -1507,6 +1507,26 @@ void set_osd_bar(int type,const char* name,double min,double max,double val) {
|
||||
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 @@ static int seek(MPContext *mpctx, double amount, int style)
|
||||
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(!mpctx->sh_video) {
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user