2

Currently I am working on some code based on VLCJ to play video content, which is working pretty fine, but I am struggling hard making the setSpu() method work.

Just to mention, when it comes to load an external subtitle, in a file apart from the video file, it is working fine. The problem appears when I try to play subtitles contained in the media file. (e.g. subs contained into a MKV file).

I read carefully GitHub post "setSpu not working #278", and I think that maybe the problem is that I am not invoking the setSpu() method correctly.

To make it simple, I am trying to make it works on the example "uk.co.caprica.vlcj.test.basic.TestPlayer".

On TestPlayer.java class, I loaded all native vlc required libs and configured the mediaPath, and mediaPlayer, so if I execute the class, the media player is built properly, and the video starts playing.

Now, to try make the subtitle work, I reused the button "subTitlesButton" on "PlayerControlsPanel.java". First of all, as the spu to be set is the ID of the TrackDescription, I added the following code, and executed to get the spuDescriptions list:

subTitlesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            System.out.println(mediaPlayer.getSpuDescriptions());
        }
    });

When the Sub-titles button is pressed, the following output is get:

spuDescriptions=[TrackDescription[id=-1,description=Deshabilitar], TrackDescription[id=3,description=Pista 1 - [Español]], TrackDescription[id=4,description=Pista 2 - [Inglés]], TrackDescription[id=5,description=Pista 3 - [Español]]]

So, to keep it simple, I just tried to add the following code and execute it:

subTitlesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            System.out.println(mediaPlayer.getSpuDescriptions());
            mediaPlayer.setSpu(3); // TrackDescription[id=3,description=Track 1 - [Spanish]]
        }
    });

The expected resault would be the subtitle "Track 1 - [Spanish]" with ID=3 to appear on screen, but nothing happens. The video goes on and is being played properly, but the sub-title is not shown.

All the other buttons, work fine when you pressed them, you get the expected result (pause, stop, play, fastforward, rewind, and so on)... so I dont get the point on why media.setSpu() is not working there.

Would be much appreciated some help :) Thanks in advance.

EDITED The exact problem was that all subtitles contained in the media file (video.mkv) were UTF8 text encoded. I tried to re-mount the video.mkv file with mkvmerge, but this program allways converts SRT files to UTF8 text format. WORKAROUND convert the SRT files to ASS subtitles format. If the video.mkv contains .ASS subtitles format, the subtitles are always loaded properly by VLC and also by vlcj libs.

Thanks a lot in advance for all the help provided.

hmonsalv
  • 23
  • 5

1 Answers1

0

If this question can be distilled down to how to use external SPU files with non-ASCII characters, you can try this:

Suppose you have some filename for your external SPU file, the filename containing non-ASCII characters, let's call this spuFileName...

Try:

String asciiFileName = new File(spuFileName)
    .toURI()
    .toASCIIString();

Or:

String asciiFileName = new File(spuFileName)
    .toURI()
    .toASCIIString()
    .replaceFirst("file:/", "file:///");

Then use asciiFileName instead when you specify the SPU file for vlcj.

If I remember correctly, LibVLC requires ASCII strings on its API. This problem can also show itself if you try and play a video with a filename that contains non-ASCII characters (vlcj detects this and handles it automatically).

But I'm not sure if this really is your problem as given the partial log you posted it looks like VLC has indeed detected the SPU tracks correctly.

On the other hand, if this suggestion does actually work, vlcj could be changed to handle this case (an external SPU file) automatically.

When actually selecting SPU for display, whether the SPU are in a separate file or contained within the video itself, the only thing that matters is the id of the SPU track. vlcj passes this id directly to the LibVLC API method. The fact that the track description strings are not being encoded directly does not matter.

In earlier versions of VLC, this id was actually the index of the SPU track - so 0, 1, 2, 3 and so on.

With the current version of VLC (this was changed around February 2013, I think this means VLC 2.1+) this was fixed to use the actual SPU track identifiers.

So depending on your version of VLC, if the track identifiers are not working for you try just passing an index instead.

caprica
  • 3,902
  • 4
  • 19
  • 39
  • (1) When it comes to the media file itself or and external subtitle that is loaded (e.g. and .ssa or .srt file), it works fine, I use "mediaPlayer.setSubTitleFile(new File("D:\\whatever_path_without_nonASCIIchars\\sub_without_nonASCIIchars.srt"));" and the subtitle appears on screen, because it can be handled they way you mentioned in the answer or just skipping nonASCII chars on the name of the file. – hmonsalv Jan 08 '15 at 15:31
  • (2) But the problems appears when the subtitle I want to set is one contained in the media file (a .mkv file for instance with several subtitles, audio tracks and so on). All subtitles tracks seems to be detected, as you can see on the output trace given by getSpuDescriptions() in the example above, but the subtitle does not appears on screen. – hmonsalv Jan 08 '15 at 15:32
  • (3) I detected as root cause, subtitles inside the media file (.mkv e.g.), being in format UTF8 will provoke the issue exposed. Is there any way to handle this, so although they are UTF8, could then be properly played and shown on screen? Or if subs .srt inside the media file are UTF8, it won't be possible to make them work? Is it a limitation on vlcj libs? Because I opened same media file in VLC, and I was able to load subtitles, but not with vlcj. Is there any media example you could share with me to make the test? Thanks a lot in advance. – hmonsalv Jan 14 '15 at 19:01
  • (4) Just to make a note of it, when I load the subtitle as a file, it works properly (I suppose it is ASCII), the issue appears when the subs I wan't to set are inside the media file (if I open the media file with program "MediaInfo", it shows clearly that the subs are UTF8 there, so the problem appears). – hmonsalv Jan 14 '15 at 19:03
  • "VLC -H" shows "--subsdec-autodetect-utf8", but it's supposed to be enabled by default. You could try passing that switch via the MediaPlayerFactory. Alternatively, can you share or link a UTF8 subtitle file that doesn't work? – caprica Jan 14 '15 at 19:16
  • The problem is that the sub itself is ASCII but when it is multiplexed into a mkv, its converted to UTF8. So... have you tried with an MKV file with subs inside the container? There is where I have the issue. Adding args "--subsdec-autodetect-utf8" to the MediaPlayerFactory, does not fix it, and an error is logged: "main decoder error: no suitable decoder module for fourcc `undf'. VLC probably does not support this sound or video format.", but this is related to the subtitle, for sure. – hmonsalv Jan 15 '15 at 00:04
  • I don't know really. vlcj does nothing itself with SPU. It makes no sense to me if it works through VLC, but not vlcj. – caprica Jan 15 '15 at 14:48
  • I'm just pretty curious about this issue I have. Have you tried with any .mkv file containing subtitles? I have tried with both mp4 and mkv containing subtitles, and the problems appeared with .mkv files only. – hmonsalv Jan 16 '15 at 17:48
  • I don't have any such sample to try. – caprica Jan 16 '15 at 18:04
  • Ok, then please, in case you find some time to try a MKV media file with subtitles inside at any given time, let me know if you have the same issue. Thanks in advance. – hmonsalv Jan 16 '15 at 18:36