Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd August 2016, 16:22   #1  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Subtitle renderer for image subtitles

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.
__________________
Buy me a "coffee" and/or hire me to write code!

Last edited by jackoneill; 25th August 2016 at 15:08.
jackoneill is offline   Reply With Quote
Old 2nd August 2016, 19:21   #2  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Nice! Thanks!
quick test with vobsub subtitles seems to work, used:
Code:
# 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.
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 2nd August 2016 at 20:15.
Selur is offline   Reply With Quote
Old 2nd August 2016, 20:30   #3  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
Selur, IIRC, DVD subtitles have 4 color indices, but what these colors are exactly is decided by the renderer.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 2nd August 2016, 20:50   #4  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by Selur View Post
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.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 3rd August 2016, 05:45   #5  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
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 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
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 3rd August 2016, 17:02   #6  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by Selur View Post
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 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/vapoursy...eleases/tag/v2

Code:
   * Add parameter 'palette', which allows the user to pass a custom palette.
   * Add parameter 'gray'.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 7th August 2016, 08:27   #7  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Okay, so libavcodec applies some custom color adjustments?

When using Vapoursynth with libsubtitle:
Code:
# 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:

using ffplay:
Code:
ffplay c:\Users\Selur\Desktop\muxed.mp4
I get:

using mplayer:
Code:
mplayer C:\Users\Selur\Desktop\Test-AC3-5.1.avi
I get:

using Avisnth and VsFilter:
Code:
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:


using using Vapoursynth with libsubtitle and gray=true:
Code:
# 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:


=> 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/vapoursy...ter/readme.rst)

Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 7th August 2016, 09:30   #8  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by Selur View Post
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/vapoursy...ter/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.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 7th August 2016, 10:01   #9  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Quote:
You're calling it correctly.
That's a relief.

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

-> off testing around with different palettes now.

Code:
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
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 7th August 2016 at 10:14.
Selur is offline   Reply With Quote
Old 17th September 2016, 14:16   #10  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
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
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 17th September 2016 at 14:22.
Selur is offline   Reply With Quote
Old 17th September 2016, 14:22   #11  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,548
Quote:
Originally Posted by Selur View Post
What happened to the filter?
https://github.com/dubhater/vapoursynth-subtitle gives a 404 now
It's here now
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 18th September 2016, 06:46   #12  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
@Myrsloik: Yes, I found that shortly before you posted.
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 16:16.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.