Using LibVLC compiled for android to display DVB subtitles from an MPEG2 stream

1.4k views Asked by At

Using the following code I was able to play back a udp stream (mpeg2 ts) which has 3 tracks (video, audio and dvb subtitles), but I am trying to retrieve the subtitle track and display it, i couldn't find any clear documentation on how to do it.

   // Create LibVLC
ArrayList<String> options = new ArrayList<String>();
        options.add("-vvv"); // verbosity
        options.add("--autoscale");

libvlc = new LibVLC(this, options);
        holder.setKeepScreenOn(true);

// Creating media player
mMediaPlayer = new MediaPlayer(libvlc);
        mMediaPlayer.setAspectRatio("16:9");
        mMediaPlayer.setEventListener(mPlayerListener);


// Seting up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
        vout.setVideoView(mSurface);

        if (mSubtitlesSurface != null)
        vout.setSubtitlesView(mSubtitlesSurface);
        vout.setWindowSize(1920,1080);
        vout.addCallback(this);
        vout.attachViews();
    Media m = new Media(libvlc, Uri.parse(media));
    mMediaPlayer.setMedia(m);
    mMediaPlayer.play();

I am trying to use mMediaPlayer.getMedia().getTrackCount() and mMediaPlayer.getSpuTracksCount() which are returning zero in all cases; even the basic audio and video tracks are not counted.

Any help on this?

Note: I compiled LibVLC from [https://wiki.videolan.org/AndroidCompile/] and got the .aar archive to my project.

3

There are 3 answers

0
nadine87 On BEST ANSWER

An argument added to options will help show the subtitles:

// Create LibVLC
    ArrayList<String> options = new ArrayList<String>();
    options.add("-vvv"); // verbosity
    options.add("--autoscale");
    args.add("--sub-track=0");//this option is used to show the first subtitle track
    libvlc = new LibVLC(this, options);
    holder.setKeepScreenOn(true);

    // Creating media player
    mMediaPlayer = new MediaPlayer(libvlc);
    mMediaPlayer.setAspectRatio("16:9");
    mMediaPlayer.setEventListener(mPlayerListener);


    // Seting up video output
    final IVLCVout vout = mMediaPlayer.getVLCVout();
    vout.setVideoView(mSurface);

    if (mSubtitlesSurface != null)
        vout.setSubtitlesView(mSubtitlesSurface);
    vout.setWindowSize(1920,1080);
    vout.addCallback(this);
    vout.attachViews();
    Media m = new Media(libvlc, Uri.parse(media));
    mMediaPlayer.setMedia(m);
    mMediaPlayer.play();
2
mfkl On

You might need to call media.parse() first, so you can be able to discover spu tracks and then set one.

0
H2O On

After a one day search i just found a proper solution for this and wanted to contribute this question with my answer.

selected answer will only show first subtitle option (if it is exist).

This one will give you full control with subtitles and audio of a media

MediaPlayer.TrackDescription[] spuTracks = mMediaPlayer.getSpuTracks();
mMediaPlayer.setSpuTrack(spuTracks[n].id);
MediaPlayer.TrackDescription[] audioTracks= mMediaPlayer.getAudioTracks();
mMediaPlayer.setAudioTrack(audioTracks[n].id);