summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-08-27 21:14:41 +0200
committerwm4 <wm4@nowhere>2016-08-27 21:14:41 +0200
commit7af6e64db748f71b472cd2b70ef7ebbe9da97859 (patch)
tree5bbf15efccf2a0a603ddb0533a51c2f7a8fbe384 /player/command.c
parenteed99d36096173baaf1964413fd070a466952598 (diff)
downloadmpv-7af6e64db748f71b472cd2b70ef7ebbe9da97859.tar.bz2
mpv-7af6e64db748f71b472cd2b70ef7ebbe9da97859.tar.xz
command: add property for current subtitle text
Requested by someone. Reuses the code for terminal subtitle display.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c22
1 files changed, 21 insertions, 1 deletions
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",