From 7af6e64db748f71b472cd2b70ef7ebbe9da97859 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 27 Aug 2016 21:14:41 +0200 Subject: command: add property for current subtitle text Requested by someone. Reuses the code for terminal subtitle display. --- DOCS/man/input.rst | 7 +++++++ player/command.c | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 8cdba41a3d..d720961226 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1668,6 +1668,13 @@ Property list ``sub-use-margins`` (RW) See ``--sub-use-margins``. +``sub-text`` + Return the current subtitle text. Formatting is stripped. If a subtitle + is selected, but no text is currently visible, or the subtitle is not + text-based (i.e. DVD/BD subtitles), an empty string is returned. + + This property is experimental and might be removed in the future. + ``ass-vsfilter-aspect-compat`` (RW) See ``--ass-vsfilter-aspect-compat``. diff --git a/player/command.c b/player/command.c index f4c10d48b9..d0e69834aa 100644 --- a/player/command.c +++ b/player/command.c @@ -2971,6 +2971,25 @@ static int mp_property_sub_pos(void *ctx, struct m_property *prop, return property_osd_helper(mpctx, prop, action, arg); } +static int mp_property_sub_text(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + struct track *track = mpctx->current_track[0][STREAM_SUB]; + struct dec_sub *sub = track ? track->d_sub : NULL; + double pts = mpctx->playback_pts; + if (!sub || pts == MP_NOPTS_VALUE) + return M_PROPERTY_UNAVAILABLE; + + pts -= mpctx->opts->sub_delay; + + char *text = sub_get_text(sub, pts); + if (!text) + text = ""; + + return m_property_strdup_ro(action, arg, text); +} + static int mp_property_cursor_autohide(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3823,6 +3842,7 @@ static const struct m_property mp_properties[] = { {"secondary-sid", mp_property_sub2}, {"sub-delay", mp_property_sub_delay}, {"sub-pos", mp_property_sub_pos}, + {"sub-text", mp_property_sub_text}, {"sub-visibility", property_osd_helper}, {"sub-forced-only", property_osd_helper}, {"sub-scale", property_osd_helper}, @@ -3924,7 +3944,7 @@ static const char *const *const mp_event_property_change[] = { "estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count", "total-avsync-change", "audio-speed-correction", "video-speed-correction", "vo-delayed-frame-count", "mistimed-frame-count", "vsync-ratio", - "estimated-display-fps", "vsync-jitter"), + "estimated-display-fps", "vsync-jitter", "sub-text"), E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params", "video-format", "video-codec", "video-bitrate", "dwidth", "dheight", "width", "height", "fps", "aspect", "vo-configured", "current-vo", -- cgit v1.2.3