Playbin2 - howto select audio and subtitle track

1,107 views
Skip to first unread message

ndesmoul

unread,
Apr 17, 2010, 6:25:33 PM4/17/10
to gstreamer-java
Hello,

I'm new to GStreamer.
I'm using a Playbin2 to play a video (which works perfectly). But with
ogm or mkv files, I would like to be able to select the sub track (or
disable it, as playbin2 select the first one present). Same thing with
audio tracks.

If I refer to the comments in PlayBin2.java, it should be possible, as
along the feathers I can read :
" - subtitle support for video files. Subtitles can be store in
external files." (I'm interested in the one too by the way)
"- stream selection between different video/audio/subtitles streams"

So it seems possible, but the problem is that I don't see how to do
that.

The GStreamer documentation about playbin2 speaks about a "current-
text" property which "Get or set the currently playing subtitle
stream. By default the first subtitle stream with data is played."

Sound good, so I tried with the set method:
playbin.set("current-text", "1"); // tried with different int values
(get an exception if not an integer value)

But it doesn't seem to have any effect. (And how to desactivate the
subs, as Playbin select automatically the first sub track ?)

As for the propriety for audio "current-audio", I don't know if it has
an effect, as on the file I have tested, even without trying to change
this propriety, the automatically chosen audio track is not always the
same...

So it is clear that I'm missing something.

Is this the good method, but the id of the tracks are wrong (how to
get the list of tracks id)?
Or is there another way to do it?

Can someone help me?

Thanks

--
You received this message because you are subscribed to the Google Groups "gstreamer-java" group.
To post to this group, send email to gstream...@googlegroups.com.
To unsubscribe from this group, send email to gstreamer-jav...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gstreamer-java?hl=en.

Andres Colubri

unread,
Apr 18, 2010, 12:45:31 PM4/18/10
to gstream...@googlegroups.com

> Sound good, so I tried with the set method:
> playbin.set("current-text", "1"); // tried with different int values
> (get an exception if not an integer value)
>
If "current-text" is an integer property, you should use

playbin.set("current-text", 1);

instead.

ndesmoul

unread,
Apr 18, 2010, 3:37:00 PM4/18/10
to gstreamer-java
Well if I put a string that can't be parse as an int, I get an
exception. So I think it is not really important.

Nevertheless I tried your suggestion, but as expected the result is
exactly the same.

In both cases if I do after:
System.out.println(playbin.get("current-text"));
System.out.println(playbin.get("current-audio"));

I get:
-1
-1

Where -1 is, according to the GStreamer doc, the "default value".

Is there a mean to know the different tracks ID number of a file, as
seen by GStreamer?

ndesmoul

unread,
Apr 18, 2010, 4:53:26 PM4/18/10
to gstreamer-java
After some more tests, it seems it works but only if I set the
properties after I do a "playbin.setState(State.PLAYING);"

But I can choose the audio (good!) and the subtitle tracks, I don't
see how to disable the subtitles. I can only set the sub track to an
existing track. Is there an easy way to just disable the subs?

Andres Colubri

unread,
Apr 18, 2010, 7:19:58 PM4/18/10
to gstream...@googlegroups.com
It seems you should use the "flags" property to disable/enable subtitle
tracks...

The only caveat is that the parameter for this property is the
GstPlayFlags enum:

http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-playbin2.html#GstPlayFlags

I'm not sure if you just can do

playbin.set("flags", f);

with:

int f = (1 << 0) | (1 << 3);

for example.

Do the other gstreamer-java developers have any insight on this one? Can
we just treat enums as ints for passing the values? Or we need to add
explicit support for enum parameters as well?

ndesmoul

unread,
Apr 19, 2010, 3:52:16 PM4/19/10
to gstreamer-java
Your solution seems to work. Thanks.

int SUB_DISABLE = (1 << 0) | (1 << 3);
int SUB_ENABLE = (1 << 2);

// to disable subs
playbin.set("flags", SUB_DISABLE);

// to enable subs
playbin.set("flags", SUB_ENABLE);

ndesmoul

unread,
Apr 23, 2010, 4:13:42 PM4/23/10
to gstreamer-java
My bad, the solution in my last message to disable the subs is no
good.
It certainly disable the subs, but the sound too (silly me not to
notice it!).

Here is the correct solution:

// sub flag
int SUB_FLAG = (1 << 2);

// You have to get the previous value of flag
// there may be a nicest way to get it as an int, but it works
int flag = new Integer(playbin.get("flags").toString()).intValue();

// to disable subs
playbin.set("flags", flag & ~SUB_FLAG);

// to enable subs
playbin.set("flags", flag | SUB_FLAG);
Reply all
Reply to author
Forward
0 new messages