[Guide]Adding SSA/ASS Subtitles

Tutorials, tips and tricks.

Moderator: moderators

[Guide]Adding SSA/ASS Subtitles

Postby ricky1252 » Mon May 20, 2013 5:08 am

Hello, I decided to make a guide for everyone on adding SSA/ASS subtitles to Subsonic. This works for windows, linux and prob mac as well with a few tweaks. I will write this gude for both windows and linux users.(I only know Debian, Im not familiar with Fedora so any linux ref will be for Debian)

Upgrading ffmpeg
For starters, I want to state ffmpeg may need to be upgraded... http://www.ffmpeg.org/download.html
download a static build with --enable libass of your windows/linux/mac build and replace it in subsonic/transcode.
Windows Users
I suggest Zeranoe's FFmpeg build (static)
C:\subsonic\transcode
Linux Users
I suggest Burek's FFmpeg build (static)
/var/subsonic/transcode/

Setting up fonts.conf File
Windows Users Only
ffmpeg needs a font config file... create a folder named fonts in transcode ie... C:\subsonic\transcode\fonts
next make a text file in the fonts folder and name it fonts.conf

open text editor and place this in the file...

fonts.conf
Code: Select all
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/fonts.conf file to configure system font access -->
<fontconfig>

<!--
   DO NOT EDIT THIS FILE.
   IT WILL BE REPLACED WHEN FONTCONFIG IS UPDATED.
   LOCAL CHANGES BELONG IN 'local.conf'.

   The intent of this standard configuration file is to be adequate for
   most environments.  If you have a reasonably normal environment and
   have found problems with this configuration, they are probably
   things that others will also want fixed.  Please submit any
   problems to the fontconfig bugzilla system located at fontconfig.org

   Note that the normal 'make install' procedure for fontconfig is to
   replace any existing fonts.conf file with the new version.  Place
   any local customizations in local.conf which this file references.

   Keith Packard
-->

<!-- Font directory list -->

   <dir>./</dir>
   <dir>WINDOWSFONTDIR</dir>
   <dir>~/.fonts</dir>

<!--
  Accept deprecated 'mono' alias, replacing it with 'monospace'
-->
   <match target="pattern">
      <test qual="any" name="family">
         <string>mono</string>
      </test>
      <edit name="family" mode="assign">
         <string>monospace</string>
      </edit>
   </match>

<!--
  Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
-->
   <match target="pattern">
      <test qual="any" name="family">
         <string>sans serif</string>
      </test>
      <edit name="family" mode="assign">
         <string>sans-serif</string>
      </edit>
   </match>

<!--
  Accept deprecated 'sans' alias, replacing it with 'sans-serif'
-->
   <match target="pattern">
      <test qual="any" name="family">
         <string>sans</string>
      </test>
      <edit name="family" mode="assign">
         <string>sans-serif</string>
      </edit>
   </match>

<!--
  Load local system customization file
-->
   <include ignore_missing="yes">conf.d</include>

<!-- Font cache directory list -->

   <cachedir>WINDOWSTEMPDIR_FONTCONFIG_CACHE</cachedir>
   <cachedir>~/.fontconfig</cachedir>

   <config>
<!--
  These are the default Unicode chars that are expected to be blank
  in fonts.  All other blank chars are assumed to be broken and
  won't appear in the resulting charsets
-->
      <blank>
         <int>0x0020</int>   <!-- SPACE -->
         <int>0x00A0</int>   <!-- NO-BREAK SPACE -->
         <int>0x00AD</int>   <!-- SOFT HYPHEN -->
         <int>0x034F</int>   <!-- COMBINING GRAPHEME JOINER -->
         <int>0x0600</int>   <!-- ARABIC NUMBER SIGN -->
         <int>0x0601</int>   <!-- ARABIC SIGN SANAH -->
         <int>0x0602</int>   <!-- ARABIC FOOTNOTE MARKER -->
         <int>0x0603</int>   <!-- ARABIC SIGN SAFHA -->
         <int>0x06DD</int>   <!-- ARABIC END OF AYAH -->
         <int>0x070F</int>   <!-- SYRIAC ABBREVIATION MARK -->
         <int>0x115F</int>   <!-- HANGUL CHOSEONG FILLER -->
         <int>0x1160</int>   <!-- HANGUL JUNGSEONG FILLER -->
         <int>0x1680</int>   <!-- OGHAM SPACE MARK -->
         <int>0x17B4</int>   <!-- KHMER VOWEL INHERENT AQ -->
         <int>0x17B5</int>   <!-- KHMER VOWEL INHERENT AA -->
         <int>0x180E</int>   <!-- MONGOLIAN VOWEL SEPARATOR -->
         <int>0x2000</int>   <!-- EN QUAD -->
         <int>0x2001</int>   <!-- EM QUAD -->
         <int>0x2002</int>   <!-- EN SPACE -->
         <int>0x2003</int>   <!-- EM SPACE -->
         <int>0x2004</int>   <!-- THREE-PER-EM SPACE -->
         <int>0x2005</int>   <!-- FOUR-PER-EM SPACE -->
         <int>0x2006</int>   <!-- SIX-PER-EM SPACE -->
         <int>0x2007</int>   <!-- FIGURE SPACE -->
         <int>0x2008</int>   <!-- PUNCTUATION SPACE -->
         <int>0x2009</int>   <!-- THIN SPACE -->
         <int>0x200A</int>   <!-- HAIR SPACE -->
         <int>0x200B</int>   <!-- ZERO WIDTH SPACE -->
         <int>0x200C</int>   <!-- ZERO WIDTH NON-JOINER -->
         <int>0x200D</int>   <!-- ZERO WIDTH JOINER -->
         <int>0x200E</int>   <!-- LEFT-TO-RIGHT MARK -->
         <int>0x200F</int>   <!-- RIGHT-TO-LEFT MARK -->
         <int>0x2028</int>   <!-- LINE SEPARATOR -->
         <int>0x2029</int>   <!-- PARAGRAPH SEPARATOR -->
         <int>0x202A</int>   <!-- LEFT-TO-RIGHT EMBEDDING -->
         <int>0x202B</int>   <!-- RIGHT-TO-LEFT EMBEDDING -->
         <int>0x202C</int>   <!-- POP DIRECTIONAL FORMATTING -->
         <int>0x202D</int>   <!-- LEFT-TO-RIGHT OVERRIDE -->
         <int>0x202E</int>   <!-- RIGHT-TO-LEFT OVERRIDE -->
         <int>0x202F</int>   <!-- NARROW NO-BREAK SPACE -->
         <int>0x205F</int>   <!-- MEDIUM MATHEMATICAL SPACE -->
         <int>0x2060</int>   <!-- WORD JOINER -->
         <int>0x2061</int>   <!-- FUNCTION APPLICATION -->
         <int>0x2062</int>   <!-- INVISIBLE TIMES -->
         <int>0x2063</int>   <!-- INVISIBLE SEPARATOR -->
         <int>0x206A</int>   <!-- INHIBIT SYMMETRIC SWAPPING -->
         <int>0x206B</int>   <!-- ACTIVATE SYMMETRIC SWAPPING -->
         <int>0x206C</int>   <!-- INHIBIT ARABIC FORM SHAPING -->
         <int>0x206D</int>   <!-- ACTIVATE ARABIC FORM SHAPING -->
         <int>0x206E</int>   <!-- NATIONAL DIGIT SHAPES -->
         <int>0x206F</int>   <!-- NOMINAL DIGIT SHAPES -->
         <int>0x2800</int>   <!-- BRAILLE PATTERN BLANK -->
         <int>0x3000</int>   <!-- IDEOGRAPHIC SPACE -->
         <int>0x3164</int>   <!-- HANGUL FILLER -->
         <int>0xFEFF</int>   <!-- ZERO WIDTH NO-BREAK SPACE -->
         <int>0xFFA0</int>   <!-- HALFWIDTH HANGUL FILLER -->
         <int>0xFFF9</int>   <!-- INTERLINEAR ANNOTATION ANCHOR -->
         <int>0xFFFA</int>   <!-- INTERLINEAR ANNOTATION SEPARATOR -->
         <int>0xFFFB</int>   <!-- INTERLINEAR ANNOTATION TERMINATOR -->
      </blank>
<!--
  Rescan configuration every 30 seconds when FcFontSetList is called
-->
      <rescan>
         <int>30</int>
      </rescan>
   </config>

</fontconfig>


Save it, and then you will need to add some environment variables.

Environment Variables
Windows Users Only
Hit the windows button and in the search type... env .... then hit enter and the env variables should pop up.
The Environment variables can also be accessed by right clicking computer or my computer properties, then hitting advanced system settings, go to advanced tab, and at the bottom will be environment variables.

in the env variables, two will need to be added...
User Variables For Admin

FC_CONFIG_DIR (this is the variable name)
C:\subsonic\transcode\fonts (this is the variable value)

and

FC_CONFIG_FILE
C:\subsonic\transcode\fonts\fonts.conf

Update Subsonic
Now that ffmpeg is updated and has access to your fonts, you will need to update subsonic war so that it will have the basefilenames interpolation string for transcoding...
subsonic-4.8-ssa-war
replace this .war with your current one, make a backup just in case.
subsonic-4.8-ssa-src src for anyone interested

Windows Users
Default is C:\Program Files (x86)\Subsonic
Linux Users
/usr/share/subsonic/ (at least for debian)

Restart Subsonic and check your jetty folder for a folder named 3434ssa (that will mean it was installed successfully)
Windows Users
C:\subsonic\jetty\3434ssa
Linux Users
/var/subsonic/jetty/3434ssa (at least for debian)

Transcoding
Now then we can move onto transcoding... First off make a folder in the directory the .war was in...name the folder sub... or if your in linux just put it in your transcoding folder
Windows Users
C:\Program Files (x86)\Subsonic\sub
Linux Users
/var/subsonic/transcode/sub

This will be the directory for all your ssa/ass subtitle files.. also let me note that a ssa/ass file is required to transcode with ffmpeg. For a fail safe, for a case theres no subtitle file, make a file in the sub folder named clean.ass with this contents

clean.ass
Code: Select all
[Script Info]
ScriptType: v4.00+
[V4+ Styles]


Now, mainly I only use the subtitles for mkv files, because thats the only container I need it for, but you can do this for any file type as long as you provide a subtitle file.

In Subsonic... Settings...Transcode...add transcoding
name: ssa/ass
convert from: mkv (make sure any filetype added here is removed from other transcodes)
convert to: flv

Windows Users
Step 1
Code: Select all
ffmpeg -i sub\clean.ass -n sub\%f.ass

Step 2
Code: Select all
ffmpeg -ss %o -i %s -b %bk -s %wx%h -copyts -af asetpts=PTS-%o/TB -vf ass='sub\\%f.ass',setpts=PTS-%o/TB -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast -threads 0 -


Linux Users
Step 1
Code: Select all
ffmpeg -i /var/subsonic/transcode/sub/clean.ass -n /var/subsonic/transcode/sub/%f.ass

Step 2
Code: Select all
ffmpeg -ss %o -i %s -b %bk -s %wx%h -copyts -af asetpts=PTS-%o/TB -vf ass='/var/subsonic/transcode/sub/%f.ass',setpts=PTS-%o/TB -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast -threads 0 -


And done! now to test to make sure everything was done correctly / working properly! play a mkv, or whatever filetype you added and if it plays then bam! you are ready to start adding SSA/ASS files. As a note, because this is a burn in transcode, these subtitles will work on all devices, like android. cheers =]


Extracting SSA/ASS files
from a container... example...
abc.mkv
Code: Select all
ffmpeg -i abc.mkv abc.ass

if theres more then one subtitle in the container first do the input
Code: Select all
ffmpeg -i abc.mkv

look at the streams it will say 0:0 is video 0:1 is audio then it could have 0:2 with another audio or subtitle and so on, find the subtitle you want and do...
example of it having subtitle on stream 0:2 0:3 and 0:4 and you want 0:3... by default, it will extract the default subtitle or lowest numbered on the stream.
Code: Select all
ffmpeg -i abc.mkv -map 0:3 abc.ass

Linux Users
To do a simple batch file...name it something like assconvert with this contents...
assconvert
Code: Select all
for m in *.mkv
   do
   ffmpeg -i "$m" -y "/var/subsonic/transcode/sub/${m%mkv}ass"
done

may need to grant execution so..
# chmod 755 assconvert
then place it in the folder and do..
# ./assconvert

Windows Users
Alternatively you can also download mkvtoolnix with mkvextractgui (place the gui in mkvtoolnix)
version 2.2.2.5 can extract fonts and all other versions should be able to extract anything else.



Adding Fonts (optional)
Windows Users
Easy! All you do is get a font like [fontname].ttf and right click and install it! simple =]

Linux Users
At least for debian, fonts folder should be /usr/share/fonts
Mainly I only needed ttf, but added a folder in truetype called myfonts... ie /usr/share/fonts/truetype/myfonts
Add your ttf's or otf's or any desired font you want then in the terminal...
Code: Select all
# cd /usr/share/fonts/truetype/myfonts
# mkfontscale && mkfontdir
# fc-cache


Trouble shooting
If you get a access denied error, first hit the play. If it still shows access denied, check the log.

If it say font config error or something stating the config file, that means of course something isnt working right with env variables (probably) Windows can be picky. Make sure the env variables and config file is exactly where I described.

If its showing something like missing .ass file or something mostlikely missing the clean.ass file, or it could be a problem with one of the characters used in the file name. I have not really looked into what characters these are and sometimes they work with some files and dont with others, it is odd but the first thing to check would be things like ! , ; ~ any of the special characters really.

If theres no sub folder in transcoding, you not be able to generate an .ass file which will generate the access denied error.

For windows, if Madsonic was not installed in the default folder, wherever it was installed,(where you to replaced the .war at) is also where you need to create the sub folder for your subtitles. By default, wherever it was installed is where the root directory is. Also take out the transcode folder in the transcode so that it says sub\ instead of transcode\sub the clean.ass will need to be moved to this directory as well.

Sometimes when converting container ssa/ass subs (older ones anyway) the .ass may have a small error... example...
random.ass
Code: Select all
[Events]
Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, TextDialogue: 0,0:00:00.52,0:00:03.71,Ep Song,,0000,0000,0000,,{\a6\i1}I want to change the world
Dialogue: 0,0:00:03.75,0:00:07.24,Ep Song,,0000,0000,0000,,{\a6}jounetsu tayasazu ni

The above example will generate an access denied error. it needs to be like this...
Code: Select all
[Events]
Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.52,0:00:03.71,Ep Song,,0000,0000,0000,,{\a6\i1}I want to change the world
Dialogue: 0,0:00:03.75,0:00:07.24,Ep Song,,0000,0000,0000,,{\a6}jounetsu tayasazu ni


Any questions or comments, or something I made a mistake on. Please let me know! Im not good at making things colorful and pretty so sorry this guide doesn't look amazing. XD
ricky1252
 
Posts: 9
Joined: Fri Mar 08, 2013 11:45 pm

Re: [Guide]Adding SSA/ASS Subtitles

Postby ricky1252 » Wed May 22, 2013 2:37 pm

Working on another project, I just noticed that %t should be equivalent to %f, however for some odd reason iv ran into errors occasionally when using %t months ago when I started using this. Never with the added %f have a ran into the same errors.. Perhaps Ill find the answer in the future.
ricky1252
 
Posts: 9
Joined: Fri Mar 08, 2013 11:45 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests