summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-21 13:16:48 +0200
committerwm4 <wm4@nowhere>2014-10-21 13:19:20 +0200
commitf0f83ff36600abc8715f3a11c31b2eeeda6c8c92 (patch)
tree38c6faba94976b08052fed67615d6680c748022e /player/command.c
parentbcc3d72995e926f899c0baa215599c50e23b9523 (diff)
downloadmpv-f0f83ff36600abc8715f3a11c31b2eeeda6c8c92.tar.bz2
mpv-f0f83ff36600abc8715f3a11c31b2eeeda6c8c92.tar.xz
player: add stream selection by ffmpeg index
Apparently using the stream index is the best way to refer to the same streams across multiple FFmpeg-using programs, even if the stream index itself is rarely meaningful in any way. For Matroska, there are some possible problems, depending how FFmpeg actually adds streams. Normally they seem to match though.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 4e74b690c9..d3d8fecbe6 100644
--- a/player/command.c
+++ b/player/command.c
@@ -1661,6 +1661,35 @@ static int property_switch_track(struct m_property *prop, int action, void *arg,
return mp_property_generic_option(mpctx, prop, action, arg);
}
+// Similar, less featured, for selecting by ff-index.
+static int property_switch_track_ff(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ enum stream_type type = (intptr_t)prop->priv;
+ if (!mpctx->num_sources)
+ return M_PROPERTY_UNAVAILABLE;
+ struct track *track = mpctx->current_track[0][type];
+
+ switch (action) {
+ case M_PROPERTY_GET:
+ *(int *) arg = track ? track->ff_index : -2;
+ return M_PROPERTY_OK;
+ case M_PROPERTY_SET: {
+ track = NULL;
+ for (int n = 0; n < mpctx->num_tracks; n++) {
+ if (mpctx->tracks[n]->ff_index == *(int *)arg) {
+ track = mpctx->tracks[n];
+ break;
+ }
+ }
+ mp_switch_track_n(mpctx, 0, type, track);
+ return M_PROPERTY_OK;
+ }
+ }
+ return mp_property_generic_option(mpctx, prop, action, arg);
+}
+
static int get_track_entry(int item, int action, void *arg, void *ctx)
{
struct MPContext *mpctx = ctx;
@@ -1686,6 +1715,7 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
.unavailable = !track->external_filename},
{"codec", SUB_PROP_STR(codec),
.unavailable = !codec},
+ {"ff-index", SUB_PROP_INT(track->ff_index)},
{0}
};
@@ -3030,6 +3060,12 @@ static const struct m_property mp_properties[] = {
{"tv-channel", mp_property_tv_channel},
{"dvb-channel", mp_property_dvb_channel},
+#define TRACK_FF(name, type) \
+ {name, property_switch_track_ff, (void *)(intptr_t)type}
+ TRACK_FF("ff-vid", STREAM_VIDEO),
+ TRACK_FF("ff-aid", STREAM_AUDIO),
+ TRACK_FF("ff-sid", STREAM_SUB),
+
M_PROPERTY_ALIAS("video", "vid"),
M_PROPERTY_ALIAS("audio", "aid"),
M_PROPERTY_ALIAS("sub", "sid"),