Set font name, size and color for selected subtitle with VLCJ

1.3k views Asked by At

Currently I am working on some code based on VLCJ to play media content.

I am focused on subtitles tracks, and I would like to add functionality to modify the font name, size and color of the subtitle being played. Is there any way to get this functionality working?

Do you know if in future vlcj releases this functionality would be added?

Thanks a lot in advance. Regards.

1

There are 1 answers

4
caprica On

There is no API in LibVLC to set subtitle attributes, so consequently there's no API in vlcj to do that either.

To see how to change subtitle attributes in VLC, go to a command-line/shell and type:

vlc -H

Then search that output for "freetype", you will see a whole bunch of switches for setting subtitle attributes, e.g.

--freetype-font
--freetype-fontsize
--freetype-opacity
--freetype-color

...and so on.

There are two ways to use these command-line switches with LibVLC/vlcj, and which way to use depends on the particular option. If it doesn't work one way, try the other.

Either:

  • when you create the MediaPlayerFactory you pass the switches as arguments; or
  • when you invoke mediaPlayer.playMedia(mrl, options) you pass the switches as options.

So pass something like:

String[] args = {
    "--freetype-color"  , "12632256",
    "--freetype-opacity", "128"
};

The situation is different e.g. with DVD subtitles - you can't change those attributes at all.

If VLC ever exposed new API to support setting of subtitle attributes, a future release of vlcj would undoubtedly add it.