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 > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 9th June 2018, 07:40   #1  |  Link
`Orum
Registered User
 
Join Date: Sep 2005
Posts: 178
Load subtitles and attachments from mkv?

I'd like to be able to do all of the following within an AviSynth script:
  1. Load a subtitle script (SSA/ASS) from a mkv container
  2. Load any attachments (fonts) from that same file
  3. Render the subtitles on the video
However, looking through the subtitling filters it doesn't look like any support this. Is there some way to do this that I'm not aware of?

Right now I'm doing an ugly workaround by extracting both the subtitles and attached fonts, installing the fonts, and then loading the subtitles from the external file via TextSub(). This involves a lot of work outside of AviSynth that I'd like to avoid, particularly the full font installation.

Edit: Even if I can't load attachments from the mkv, just loading subtitles would still be helpful.
__________________
My filters: DupStep | PointSize

Last edited by `Orum; 9th June 2018 at 08:36.
`Orum is offline   Reply With Quote
Old 10th June 2018, 06:57   #2  |  Link
Yanak
Registered User
 
Join Date: Oct 2011
Posts: 275
Hello,

For the font installation you can maybe skip it with avisynth+, it can load non-installed fonts if you provide the name of the font and the location path, for example :

Code:
Subtitle("SomeText", font="Olde English", font_filename="H:\fonts\OldeEnglish.ttf", size=50, text_color=$FF000000, halo_color=color_black)
see : http://forum.doom9.org/showthread.ph...06#post1801206

The link says that once the font is loaded there is no more need to give the name or path so it might be possible to then use it with some subtitle rendering plugins once loaded, maybe making a fake empty subtitle first , maybe only applied on the first frame, then trying to see if your plugins used to render the subtitles can then use the non installed font that was loaded using this trick. ( or creating a function loading the fonts just to trigger it maybe)

I use non installed fonts to render text using avisynth native functions but never tried with subtitles plugins, need some testing i guess.

For the necessity to demux the MKV and extract the subs + embedded fonts i don't know if it's possible directly in avisynth, some others will probably have answers to this.

Last edited by Yanak; 10th June 2018 at 07:14.
Yanak is offline   Reply With Quote
Old 10th June 2018, 07:33   #3  |  Link
`Orum
Registered User
 
Join Date: Sep 2005
Posts: 178
Quote:
Originally Posted by Yanak View Post
The link says that once the font is loaded there is no more need to give the name or path so it might be possible to then use it with some subtitle rendering plugins once loaded, maybe making a fake empty subtitle first , maybe only applied on the first frame, then trying to see if your plugins used to render the subtitles can then use the non installed font that was loaded using this trick. ( or creating a function loading the fonts just to trigger it maybe)
I'd be quite surprised if this works, as I suspect the font is only "loaded" in the context of Subtitle() itself (and not for TextSub()), but I can give it a try when I get home.
__________________
My filters: DupStep | PointSize
`Orum is offline   Reply With Quote
Old 10th June 2018, 07:45   #4  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
attach the fonts with the .ass using aegisub then load it with TextSub/TextSubmod

it work with vsfiltermod and xyvsfilter, other may not since there was some bug that fixed later
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 10th June 2018, 09:23   #5  |  Link
Yanak
Registered User
 
Join Date: Oct 2011
Posts: 275
Just tested this quickly :

Code:
LoadPlugin("H:\avs\DSS2mod\DSS2.dll")
Loadplugin("H:\VSFilterMod.dll")

DSS2("H:\test.mkv")

Subtitle("0", first_frame=0, last_frame=1,\
font="Pacific Again", font_filename="H:\Pacific Again.ttf", \
text_color=$FF000000, halo_color=$FF000000)

TextSubMod("H:\testsub.ass")
fake subtitle applied on first frame with transparent colors for text and halo, then using vsfiltermod (version r5 i found in a link not long ago in this forum ).

Probably only adding a space for the text will be enough and then no need for the colors part:
Code:
Subtitle(" ", first_frame=0, last_frame=1, font="Pacific Again", font_filename="H:\Pacific Again.ttf")
keeping first and last frame option to not slowdown the thing by doing this on the first frame only, if it have any significant speed impact to start with.

In the .ass file there is this, only thing i done is a manual editing to test the non installed font, was Arial before "Pacific Again" :
Quote:
[Script Info]
; Script generated by FFmpeg/Lavc57.107.100
ScriptType: v4.00+
PlayResX: 384
PlayResY: 288

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Pacific Again,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
etc...
Seems to work, the script launched in avspmod or MPC-HC displays correctly the non-installed font on subtitles. ( also tried with the font "Pacific Again.ttf" loaded from a totally different path, on another drive just to be sure )

Don't know if i am missing something or doing something wrong or if i am lucky but seems to work ¯\_(ツ)_/¯

Last edited by Yanak; 10th June 2018 at 10:24.
Yanak is offline   Reply With Quote
Old 10th June 2018, 10:38   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Also on Wiki,
Not processing frames plugin with Avisynth AtExit function
Quote:
This plugin does not process frames. It loads a font into Windows and automatically unloads it after avisynth is done running.
To run code at the end of the script, it registers an env->AtExit procedure.
http://avisynth.nl/index.php/Filter_SDK/Non-clip_sample

AtExit:- http://avisynth.nl/index.php/Filter_...lus_API#AtExit
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 12th June 2018, 14:46   #7  |  Link
`Orum
Registered User
 
Join Date: Sep 2005
Posts: 178
Yep, seems to work, thanks. The only downside is I still have to extract the subtitles and attachments separately, but I don't think there's a way around that (currently, anyway).
__________________
My filters: DupStep | PointSize
`Orum is offline   Reply With Quote
Old 12th June 2018, 16:59   #8  |  Link
Yanak
Registered User
 
Join Date: Oct 2011
Posts: 275
Good, at least this is one less thing to deal with, I don't know a way to read and extract directly without passing by the demuxing tool step, nobody answered to this so i doubt it is even possible from avisynth directly.

Probably making a script or batch file that will execute the demuxing using something like mkvextract to get all files needed and then maybe having this script pre-writing the start of .avs script too will make it way easier if you have a lot of those tasks to do...

Inside Staxrip i used to have a small powershell script that allowed me to browse for any non-installed font on my computer and add some watermark text into a video with avisytnh "Subtitle" function, and the power-shell script was reading directly the name of the font ( as it often differs from the font file name itself ) and adding it + the path i browsed the font to my staxrip filter.

Long time i did not mess with this and hard to recall everything i made at this time, but this is a part of the powsrshell script used in staxrip in case it could help if you decide to go this way, at least you have here how to get the font name from the tff file :
Code:
$FileBrowse = New-Object System.Windows.Forms.OpenFileDialog -Property @{
    Multiselect = $false
    Filter = 'fonts (*.ttf)|*.ttf' } # File type(s)
[void]$FileBrowse.ShowDialog()

#Get the font name from the browsed file	
if ($FileBrowse.FileNames -like "*\*") {$file = "`"$($FileBrowse.FileName)`""
Add-Type -AssemblyName System.Drawing
$getfontname = new-object System.Drawing.Text.PrivateFontCollection
$getfontname.AddFontFile($FileBrowse.FileNames)
$selectfont = $getfontname.Families[-1].Name
$selectedfont = "`"$($getfontname.Families[-1].Name)`""
$font = "font=$selectedfont, font_filename=$file"

It is probably possible to do something a bit more complex that will first extract the .ass subtitle + the font ( and the cover pictures if there is some or if it's needed ) then read the font file name from the tff file and create a starting avisynth script, well i guess, like i said long time I didn't put my hands in this and my brain is rusty now

But probably a simple script or batch file would ease your task by automating the extraction process.
Good luck

Last edited by Yanak; 12th June 2018 at 17:25.
Yanak 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 20:48.


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