Log in

View Full Version : Subtitle renderer for image subtitles


jackoneill
2nd August 2016, 16:22
Edit: This plugin is shipped with VapourSynth since version R33, under the name Subtext.



It supports demuxed VOBSUB and PGS subtitles.

Let me know how it works. I tested it about as much as usual, which is not a lot.

Selur
2nd August 2016, 19:21
Nice! Thanks!
quick test with vobsub subtitles seems to work, used:
# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading Plugins
core.std.LoadPlugin(path="G:/Hybrid/Vapoursynth/vapoursynth64/plugins/SubtitleFilter/LibSubtitle/libsubtitle.dll")
core.std.LoadPlugin(path="G:/Hybrid/Vapoursynth/vapoursynth64/plugins/SourceFilter/FFMS2/ffms2.dll")
# Loading Source: F:\TestClips&Co\Test-AC3-5.1.avi
clip = core.ffms2.Source(source="F:/TESTCL~1/TEST-A~1.AVI",cachefile="H:/Temp/avi_54a4199c1a3d3b1476ea1d15dc267332_4827.ffindex",fpsnum=25)
# loading subtitle TITLE_1_0_lang_en from ElephantsDream with LibSubtitle
subs = core.sub.ImageFile(clip=clip, file="H:/Output/TITLE_1_0_lang_en.idx")
alpha = core.std.PropToClip(subs)
subs = core.resize.Bicubic(subs, width=clip.width, height=clip.height, format=clip.format.id, matrix_s="470bg")
gray_format = core.register_format(vs.GRAY, clip.format.sample_type, clip.format.bits_per_sample, 0, 0)
alpha = core.resize.Bicubic(alpha, width=clip.width, height=clip.height, format=gray_format.id)
clip = core.std.MaskedMerge(clip, subs, alpha)
# Output
clip.set_output()
only strange thing is that the subtitle borders shows white in mplayer and yellow when using the vapoursynth script.

Mystery Keeper
2nd August 2016, 20:30
Selur, IIRC, DVD subtitles have 4 color indices, but what these colors are exactly is decided by the renderer.

jackoneill
2nd August 2016, 20:50
Nice! Thanks!

only strange thing is that the subtitle borders shows white in mplayer and yellow when using the vapoursynth script.

This filter just displays whatever ffmpeg gives it. mplayer probably does more.

Selur
3rd August 2016, 05:45
Muxed the subtitles with the video stream into an mp4 and played the file with mplayer and ffplayer to compare and they both displayed the same white borders.
Uploaded the files (Test-AC3-5.1.avi, TITLE_1_0_lang_en.idx/.sub and muxed.mp4) I used to my GoogleDrive (https://drive.google.com/folderview?id=0B_WxUS1XGCPASUZibG5XZkRfeTg&usp=sharing) as subtitleTest.7z
(no clue how to hardcode idx/sub subtitles with ffmpeg, but since ffplay displays the colors correctly on the muxed file I guess there is something wrong with the filter,...)

Cu Selur

jackoneill
3rd August 2016, 17:02
Muxed the subtitles with the video stream into an mp4 and played the file with mplayer and ffplayer to compare and they both displayed the same white borders.
Uploaded the files (Test-AC3-5.1.avi, TITLE_1_0_lang_en.idx/.sub and muxed.mp4) I used to my GoogleDrive (https://drive.google.com/folderview?id=0B_WxUS1XGCPASUZibG5XZkRfeTg&usp=sharing) as subtitleTest.7z
(no clue how to hardcode idx/sub subtitles with ffmpeg, but since ffplay displays the colors correctly on the muxed file I guess there is something wrong with the filter,...)

Cu Selur

I have it on good authority that VOBSUBs are always gray in mplayer. By default, this filter displays exactly what libavcodec produces. Anyway, with v2 you can pick the colours yourself or make them all gray.

https://github.com/dubhater/vapoursynth-subtitle/releases/tag/v2


* Add parameter 'palette', which allows the user to pass a custom palette.
* Add parameter 'gray'.

Selur
7th August 2016, 08:27
Okay, so libavcodec applies some custom color adjustments?

When using Vapoursynth with libsubtitle:
# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading Plugins
core.std.LoadPlugin(path="G:/Hybrid/Vapoursynth/vapoursynth64/plugins/SubtitleFilter/LibSubtitle/libsubtitle.dll")
core.std.LoadPlugin(path="G:/Hybrid/Vapoursynth/vapoursynth64/plugins/SourceFilter/LSmashSource/vslsmashsource.dll")
# Loading Source: H:/Output/Test-AC3-5.1.avi
clip = core.lsmas.LWLibavSource(source="H:/Output/Test-AC3-5.1.avi", cache=0)
# loading subtitle TITLE_1_0_lang_en with LibSubtitle
subs = core.sub.ImageFile(clip=clip, file="H:/Output/TITLE_1_0_lang_en.idx")
alpha = core.std.PropToClip(subs)
subs = core.resize.Bicubic(subs, width=clip.width, height=clip.height, format=clip.format.id, matrix_s="470bg")
gray_format = core.register_format(vs.GRAY, clip.format.sample_type, clip.format.bits_per_sample, 0, 0)
alpha = core.resize.Bicubic(alpha, width=clip.width, height=clip.height, format=gray_format.id)
clip = core.std.MaskedMerge(clip, subs, alpha)
# Output
clip.set_output()
I get:
https://s7.postimg.org/4d25tzukr/libsubtitle.png
using ffplay:
ffplay c:\Users\Selur\Desktop\muxed.mp4
I get:
https://s8.postimg.org/vfhn8m1ud/ffplay.png
using mplayer:
mplayer C:\Users\Selur\Desktop\Test-AC3-5.1.avi
I get:
https://s7.postimg.org/9lrbg1bwr/mplayer.png
using Avisnth and VsFilter:
LoadCPlugin("G:\Hybrid\AVISYN~1\ffms2.dll")
LoadPlugin("G:\Hybrid\AVISYN~1\VSFilter.dll")
# loading source: C:\Users\Selur\Desktop\Test-AC3-5.1.avi
FFVideoSource("C:\Users\Selur\Desktop\TEST-A~1.AVI",cachefile="H:\Temp\avi_3c69763e8478b88d8cc19d0971dbb14d_4827_1_0.ffindex",fpsnum=25)
# embedding subtitles
VobSub("H:\Output\TITLE_1_0_lang_en")
return last
I get:
https://s7.postimg.org/xemebdkgr/avisynth_vsfilter.png

using using Vapoursynth with libsubtitle and gray=true:
# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading Plugins
core.std.LoadPlugin(path="G:/Hybrid/Vapoursynth/vapoursynth64/plugins/SubtitleFilter/LibSubtitle/libsubtitle.dll")
core.std.LoadPlugin(path="G:/Hybrid/Vapoursynth/vapoursynth64/plugins/SourceFilter/LSmashSource/vslsmashsource.dll")
# Loading Source: H:/Output/Test-AC3-5.1.avi
clip = core.lsmas.LWLibavSource(source="H:/Output/Test-AC3-5.1.avi", cache=0)
# loading subtitle TITLE_1_0_lang_en with LibSubtitle
subs = core.sub.ImageFile(clip=clip, file="H:/Output/TITLE_1_0_lang_en.idx",gray=True)
alpha = core.std.PropToClip(subs)
subs = core.resize.Bicubic(subs, width=clip.width, height=clip.height, format=clip.format.id, matrix_s="470bg")
gray_format = core.register_format(vs.GRAY, clip.format.sample_type, clip.format.bits_per_sample, 0, 0)
alpha = core.resize.Bicubic(alpha, width=clip.width, height=clip.height, format=gray_format.id)
clip = core.std.MaskedMerge(clip, subs, alpha)
# Output
clip.set_output()
gives me:
https://s7.postimg.org/hxy9tega3/libsubtitle_gray.png

=> Do you by chance know what custom palette ffplay/mplayer/vsfilter are using?

Or is there something wrong with the way I call libsubtitle in Vapoursynth and apply it to the clip? (I followed the example from https://github.com/dubhater/vapoursynth-subtitle/blob/master/readme.rst)

Cu Selur

jackoneill
7th August 2016, 09:30
Okay, so libavcodec applies some custom color adjustments?

=> Do you by chance know what custom palette ffplay/mplayer/vsfilter are using?

Or is there something wrong with the way I call libsubtitle in Vapoursynth and apply it to the clip? (I followed the example from https://github.com/dubhater/vapoursynth-subtitle/blob/master/readme.rst)

Cu Selur

I don't know what libavcodec, ffplay, mplayer, and vsfilter do.

You're calling it correctly.

Tip: the yellow border is probably the fourth element of the palette.

Selur
7th August 2016, 10:01
You're calling it correctly.
That's a relief. :)

Tip: the yellow border is probably the fourth element of the palette.
Thanks for the tip.

-> off testing around with different palettes now. :)

palette=[rgba(0, 0, 0), rgba(255, 255, 255), rgba(0, 0, 0), rgba(0, 0, 0)]
does seem to do the trick :)

Cu Selur

Selur
17th September 2016, 14:16
What happened to the filter?
https://github.com/dubhater/vapoursynth-subtitle gives a 404 now :(
ah, seems like it got included into http://www.vapoursynth.com/doc/plugins/subtext.html

Myrsloik
17th September 2016, 14:22
What happened to the filter?
https://github.com/dubhater/vapoursynth-subtitle gives a 404 now :(

It's here now (http://www.vapoursynth.com/doc/plugins/subtext.html#sub.ImageFile)

Selur
18th September 2016, 06:46
@Myrsloik: Yes, I found that shortly before you posted. ;)