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 > General > Subtitles
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th April 2009, 15:16   #1  |  Link
Ulf
Registered User
 
Join Date: Sep 2008
Location: Sweden
Posts: 66
MaestroBDSubs - Creating high quality Blu-ray subtitles

Introduction

With both BDSupEdit and BDSup2Sub supporting BDN XML import and SUP creation, I'll share my tools for creating high quality BD subtitles. The programming language is PostScript (!) and the tools are in the form of Windows batch files. The tools don't render any bitmaps with subtitles, but are using MaestroSBT for this task. The tools create BDN XML file + PNG files for Scenarist import which now can be converted to a BD SUP file by BDSupEdit or BDSup2Sub. MaestroSBT is really intended for DVD subtitle creation (4-bit bitmaps). By creating oversized bitmaps that are scaled down, we'll achieve nice looking antialiased subtitle bitmaps.

A short description of the tools:

SRT_to_SSA-BR.bat - Converts an SRT subtitle file to an SSA file for MaestroSBT input
MaestroBRSubs.bat - Converts output from MaestroSBT to BDN XML file and 8-bit PNG's (trimmed with alpha transparency)
test_AVS_BDN.bat - Displays an AVS file (1080p, 1440x1080, 720p, 576i or 480i) with one selected subtitle overlayed the clip (just as it will look in the end), and tests alternate X/Y adjustments for the subtitles.
modify_XML_from_SRT.bat - Sets new timings in a BDN XML file from timings in a SRT file
modify_XML_XY_position.bat - Modifies position of the subtitle bitmaps in the BDN XML file
XML_PNG_to_SUP.bat - Converts BDN XML file + PNG's to SUP
INI_PATH.BAT - example file specifying the path's to the executables the batch files are using (see below)

Download

See attachment MaestroBRSubs_v1_0.zip
MaestroBRSubs_v1_0.zip

Programs used in the batch files:

GPL GhostScript - Postscript interpreter (ver 8.63) , http://sourceforge.net/project/showf...?group_id=1897
ImageMagick (Q8 version) - bitmap image manipulation, http://www.imagemagick.org
(Q8 version is much faster than Q16)
Virtualdub - video processing application, http://sourceforge.net/project/showf...?group_id=9649
BDSup2Sub - BDN XML to SUP conversion - http://forum.doom9.org/showthread.php?t=145277

You'll also need MaestroSBT:

MaestroSBT - subtitle BMP generation, http://sourceforge.net/projects/maestrosbt/

Preparations before using the batch files:

There are two ways of specifying the path's to the executables for the batch files (the second one is the recommended).
1. Edit each .BAT file and specify the path's.
2. Create one file with all path's specified (called by each of the batch files). All the batch files are looking for the file %ALLUSERSPROFILE%\INI_PATH.bat. This usually translates to C:\Documents and Settings\All Users\INI_PATH.BAT (write %ALLUSERSPROFILE% in an explorer window). Look in the zip file for an example of "INI_PATH.BAT".

Description of the tools in more detail:

SRT_to_SSA-BR.bat
Converts an SRT subtitle file to an SSA file for MaestroSBT input. Just drop SRT file(s) in the batch file and specify frame rate. The SSA file has four different styles predefined:
Style1 - Style4. Look in the batch file for more information on the styles. Default settings of font, font size, default style etc can be changed in the batch file. Bottom/top/left margins are not important to set other than the defaults. The tool modify_XML_XY_position.bat allows you to change these afterwards.
SRT_to_SSA-BR.bat is looking for a file SRT_to_SSA-BR.ini in the same folder as the SRT file(s) and calls it as a batch file if found. If for example, the SRT_to_SSA-BR.ini contains the lines:

set FONT=Tahoma
set FONTSIZE=90
set OUTLINE=4
set LINESPACE=110
set BOLD=1

this will override the corresponding settings in SRT_to_SSA-BR.bat.
SRT_to_SSA-BR.bat will create a folder with the same name as the SRT file (without the .SRT suffix). When opening the SSA file in MaestroSBT it's just to click on the button "Generate". MastroSBT will create BMP's and a SST file containing in/out times in the same format as expected in a BDN XML file. Note that MastroSBT is slow, especially for the large bitmaps we are demanding.

MaestroBRSubs.bat
Drop folder(s) with BMP's/SST in the batch file. You specify to what format the bitmaps are to be scaled (1080p, 720p, 576i or 480i), the frame rate and if you want the subtitles to be centered (good if you have left adjusted subs that you'll want centered). MaestroBRSubs.bat creates a file "BATCH.BAT" that actually does the scaling, trimming etc when executed. The end result is a BDN XML file and 8-bit trimmed PNG's with alpha transparency. These are good for Scenarist HDMV, BDSupEdit or BDSup2Sub import.
MaestroBRSubs.bat contains default settings of the font and anti-alias color (you can change these by editing the batch file).

test_AVS_BDN.bat

Move our AVS file (1080p, 1440x1080, 720p, 576i or 480i) to the same folder containing the folder with BDN XML/PNG's. Mark the AVS file and the subtitle folder and drop them both in the batch file. This will display the AVS clip with one subtitle overlayed the clip. Various X/Y displacements of the subtitles can be tested.

modify_XML_XY_position.bat
Drop BDN XML file to modify horizontal and vertical position of the subtitles. For vertical positioning, sub- and top titles can be modified separately (if you move a subtitle 20 pixels up you'll probably want to move the top titles 20 pixels down).

modify_XML_from_SRT.bat
If you need to change the timings of the subtitles after the subtitles has been converted to BDN XML + PNG's, the batch file provides an easy way to do this. Put the SRT with the new timings in the same folder as the XML file. Drop both of them in the batch file and a new XML file is created.

XML_PNG_to_SUP.bat

Drop folder with BDN XML/PNG's in the batch file for conversion to SUP file by BDSup2Sub.

Technical details


What MaestroBRSubs.bat does:
1. Modifies the BMP's palette to preferred font and anti-alias colors and sets the background to red.
2. Scales and trims the bitmaps with the help of ImageMagick. The dimensions of the bitmaps and the trimming coordinates are extracted from the PNG files.
3. A PostScript program reads the Palette from a PNG and creates a new B/W palette and a tRNS chunk (transparency) based on the red content in the palette. Calculation of crc-32 checksums for the new PNG chunks are made in PostScript.
4. A PostScript program creates the BDN/XML file based on data from the SST file and PNG's.

For an example of a SUP created by these tools, take a look at the attachment to post #16 here.

Last edited by Ulf; 20th April 2009 at 15:23.
Ulf is offline   Reply With Quote
Old 23rd April 2009, 01:14   #2  |  Link
OptimusX
Registered User
 
Join Date: Apr 2007
Posts: 20
This is a lot of work, and I really appreciate you sharing this. I'm currently working on a DVD project, but with this tool I'm going to make my next project an AVCHD I've always wanted to do. That'll happen in the next 1 to 2 weeks, and I'll post how everything turns out here.
OptimusX is offline   Reply With Quote
Old 27th April 2009, 21:32   #3  |  Link
shon3i
BluRay Maniac
 
shon3i's Avatar
 
Join Date: Dec 2005
Posts: 2,419
This is fantastic, Ulf thank you for realy hard work, and ofcourse all devs of app's which make this things possible.

I found two bugs in SRT_to_SSA-BR.bat:

1. when i select 23.976fps and when i load ssa into scenarist and look into Timing, fps in is 23.976 but fps out is 24, should be that two values same?
2. in saved ssa output script is wrong, if i have for example C:\ZZZ\ and in ZZZ i put files, output script will be set C:\ZZZ\ZZZ\ which i must create manualy otherwise MaestroSBT on generating will give error message that can't find specified file or something like that.
shon3i is offline   Reply With Quote
Old 28th April 2009, 06:37   #4  |  Link
Ulf
Registered User
 
Join Date: Sep 2008
Location: Sweden
Posts: 66
Quote:
Originally Posted by shon3i View Post
1. when i select 23.976fps and when i load ssa into scenarist and look into Timing, fps in is 23.976 but fps out is 24, should be that two values same?
No, for 23.976, 29.97 and 59.94 fps, the output fps should be 24, 30 and 60 respectively. The timings in the XML file is given as if the frame rate is 24, 30 and 60 respectively in these cases - probably in order to specify the exact frames where the subs goes in/out.

Quote:
Originally Posted by shon3i View Post
2. in saved ssa output script is wrong, if i have for example C:\ZZZ\ and in ZZZ i put files, output script will be set C:\ZZZ\ZZZ\ which i must create manualy otherwise MaestroSBT on generating will give error message that can't find specified file or something like that.
Sorry, cant reproduce that behaviour (I'm running XP). Could be a difference in behaviour XP/Vista in case you are running Vista.

Edit: You are supposed to drop the SRT file(s) in the batch file (SRT_to_SSA-BR.bat), not a folder containing the SRT's.

Last edited by Ulf; 28th April 2009 at 07:58.
Ulf is offline   Reply With Quote
Old 28th April 2009, 14:46   #5  |  Link
Oleg Rode
Registered User
 
Oleg Rode's Avatar
 
Join Date: Jun 2008
Location: Kiev, Ukraine
Posts: 92
It is a very good job! Thank you for it!

I am a shame to ask, but... Any hopes for ASS subs support?

Sorry for my English...
Oleg Rode is offline   Reply With Quote
Old 28th April 2009, 16:08   #6  |  Link
Ulf
Registered User
 
Join Date: Sep 2008
Location: Sweden
Posts: 66
Quote:
Originally Posted by Oleg Rode View Post
I am a shame to ask, but... Any hopes for ASS subs support?
No, I'm afraid not. The conversion by MaestroSBT is based on the SSA format with certain additions to the format specific to MaestroSBT that makes it very powerful (ASS is very similar to SSA). You can for instance specify line spacing and italics corrections with these additions to the SSA format. With ASS you can't do that (at least to my knowledge).

If you have an ASS file where you are using several different styles I can recommend you the following:
Convert your ASS to SRT and convert that with my tool to SSA. You can probably paste the portion with the subs from your ASS to the SSA file. You'll have to define the styles you are using (look at the predefined styles Style1 - Style4).
Ulf is offline   Reply With Quote
Old 28th April 2009, 16:50   #7  |  Link
ps auxw
Registered User
 
Join Date: Apr 2009
Posts: 102
Quote:
Originally Posted by Oleg Rode View Post
I am a shame to ask, but... Any hopes for ASS subs support?
If you are using ASS specific styling that is incompatible with SSA, and would like to preserve it, I suggest you use AviSynth with VSFilter 2.39's MaskSub function to render the subs, then use avs2bdnxml to convert to BDN XML.

After this you can use either BDSupEdit, or BDSup2Sub to convert that to BD-Sup. Ulf's batch files should work too.
ps auxw is offline   Reply With Quote
Old 28th April 2009, 21:19   #8  |  Link
rica
Registered User
 
Join Date: Mar 2008
Posts: 2,021
Ulf, i'd like to undertand why you've given up this method and script?
Anything else more in your new method? Or in other words what's over than your ex-method?

(I did get the best results once with that.)


Code:
@REM Conversion of BDM XML file and PNG files to 720p.
@REM Drop folder(s) with PNG files and BDN XML file in this BAT-file.
@REM Use "SUPRead" to save the bitmaps as PNG from a "sup" subtitle file.

@REM ImageMagick ("convert.exe") has the ability to read the tranparency data
@REM stored in an indexed PNG file (saved in the tRNS chunk in a PGN file).
@REM Bitmaps saved from ".sup" by "SUPread" contains the transparency,
@REM but this information is disregarded by GIMP, Photoshop etc.
@REM ImageMagick opens the file and uses the tranparency data to form a 32 bit
@REM PNG file with variable transparency. The script below scales the image to
@REM 1280x720 and saves it. Observe! "pngnq.exe" can only do a proper conversion
@REM if the downscaling in ImageMagick is done by the simpler downscaling
@REM command "-scale 1280" instead of "-resize 1280".
@REM ImageMagick: http://www.imagemagick.org

@REM "pngnq.exe" converts the PNG file to an indexed 8-bit PNG file with
@REM full transparency retained (saved in the tRNS chunk).
@REM "pngnq.exe" requres the following DLLs: libpng13.dll and zlib1.dll
@REM pngnq: http://pngnq.sourceforge.net/
@REM libpng13.dll: http://www.cybertherial.com/pngnq/libpng13.dll
@REM zlib1.dll: http://www.dll-files.com/dllindex/dll-files.shtml?zlib1

@REM "sed.exe" is the GNU sed editor.
@REM sed.exe: http://sourceforge.net/projects/gnuwin32/

@REM The resulting files can be imported as BDN assets in Sonic Scenarist.
@REM -------------------------------------------------------
set CONV_EXE=C:\Program Files\ImageMagick\convert.exe
set PNGNQ_EXE=C:\Program Files\pngtools\pngnq.exe
set SED_EXE=C:\Program Files\GnuWin32\bin\sed.exe
@REM -------------------------------------------------------
set CONV_OPT=-scale 1280
set SED_OPT="10,12d;s/"1080p"/"720p"/g;s/"1920"/"1280"/g;s/"1080"/"720"/g"
@REM -------------------------------------------------------
cls
:NEXT
IF EXIST "%~f1\_CONVERTED.txt" goto :SKIP
FOR %%a IN ("%~f1\*.png") DO (
  start "CONVERT" /belownormal /b /w "%CONV_EXE%" "%%a" %CONV_OPT% "%%a.png"
  start "PNGNQ" /belownormal /b /w "%PNGNQ_EXE%" -f "%%a.png"
  del /q "%%a"
  del /q "%%a.png"
  copy "%%a-nq8.png" "%%a"
  del /q "%%a-nq8.png"
)
FOR %%a IN ("%~f1\*.xml") DO (
  "%SED_EXE%" %SED_OPT% "%%a" > "%~f1\720p_subtitles.bdn.xml"
)
echo Files converted to 720p > "%~f1\_CONVERTED.txt"
:SKIP
shift
IF NOT "%1"=="" goto :NEXT
@REM -------------------------------------------------------

Last edited by rica; 28th April 2009 at 21:37.
rica is offline   Reply With Quote
Old 28th April 2009, 21:42   #9  |  Link
Ulf
Registered User
 
Join Date: Sep 2008
Location: Sweden
Posts: 66
Quote:
Originally Posted by rica View Post
Ulf, i'd like to undertand why you've given up this method and script?
Anything else more in your new method?
That script is now obsolete with BDSup2Sub and BDSupEdit on the scene. They do a fast and accurate job in scaling 1080p BD SUP's down to 720p (amongst other things).

MaestroBDSubs is all about creating your own high quality SUP's, starting from an SRT file.
Ulf is offline   Reply With Quote
Old 28th April 2009, 21:45   #10  |  Link
rica
Registered User
 
Join Date: Mar 2008
Posts: 2,021
Quote:
Originally Posted by Ulf View Post
That script is now obsolete with BDSup2Sub and BDSupEdit on the scene. They do a fast and accurate job in scaling 1080p BD SUP's down to 720p (amongst other things).

MaestroBDSubs is all about creating your own high quality SUP's, starting from an SRT file.
Thanks for the explanation. I'll give it a go.
rica is offline   Reply With Quote
Old 4th May 2009, 16:17   #11  |  Link
shon3i
BluRay Maniac
 
shon3i's Avatar
 
Join Date: Dec 2005
Posts: 2,419
Quote:
Sorry, cant reproduce that behaviour (I'm running XP). Could be a difference in behaviour XP/Vista in case you are running Vista.
Sorry, my mistake everything work perfect
shon3i is offline   Reply With Quote
Old 12th June 2009, 11:56   #12  |  Link
tkamp
Registered User
 
Join Date: Aug 2007
Location: Denmark
Posts: 10
Hi, I'm using these script for converting DVD to BD (multiAVCHD), but with upgraded subs.
I want to use the test script, where there should be some avs-files...
Where are they, and is it possible to optain them?

Regards
Thomas Kamp
tkamp is offline   Reply With Quote
Old 12th June 2009, 13:32   #13  |  Link
Ulf
Registered User
 
Join Date: Sep 2008
Location: Sweden
Posts: 66
Quote:
Originally Posted by tkamp View Post
Hi, I'm using these script for converting DVD to BD (multiAVCHD), but with upgraded subs.
I want to use the test script, where there should be some avs-files...
Where are they, and is it possible to optain them?
Are you referring to the script test_AVS_BDN.bat?

Assuming you have a folder with subtitles (PNG's + BDN XML file) and an AVS file with the BD video, test_AVS_BDN.bat allows you to preview the video with a subtitle overlayed in Virtualdub.

The AVS file you'll have to create yourself. Search the forum how to create av AVS (AviSynth) file from BD content.
Ulf is offline   Reply With Quote
Old 15th June 2009, 20:15   #14  |  Link
tkamp
Registered User
 
Join Date: Aug 2007
Location: Denmark
Posts: 10
Hi Ulf
OK - know I got that AVS-file working - Thanks!

New problem...
I get an "Error: /typecheck in --cvi--" from GhostScript whenever I drag the XML-file into the modify_XML_XY_position.bat
Is there any solution for this?
(I'm using GhostScript 8.64 in stead of 8.63)
tkamp is offline   Reply With Quote
Old 24th August 2009, 13:14   #15  |  Link
Ulf
Registered User
 
Join Date: Sep 2008
Location: Sweden
Posts: 66
I have tested the scripts on a Vista (32 bit) machine and encountered errors with ImageMagick graphics routines (convert.exe) that doesn't show up on WinXP. After testing older versions of ImageMagick, I found a version that works flawlessly. The version is 6.5.3-8 and can be downloaded from:

http://image_magick.veidrodis.com/im...ows-static.exe

The only file needed from the installation is "convert.exe" (i.e. one can uninstall ImageMagick and just keep the executable).
Ulf is offline   Reply With Quote
Old 4th August 2010, 10:19   #16  |  Link
jd213
Registered User
 
Join Date: Jan 2007
Posts: 15
Quote:
Originally Posted by Ulf View Post
What MaestroBRSubs.bat does:
1. Modifies the BMP's palette to preferred font and anti-alias colors and sets the background to red.
2. Scales and trims the bitmaps with the help of ImageMagick. The dimensions of the bitmaps and the trimming coordinates are extracted from the PNG files.
3. A PostScript program reads the Palette from a PNG and creates a new B/W palette and a tRNS chunk (transparency) based on the red content in the palette. Calculation of crc-32 checksums for the new PNG chunks are made in PostScript.
4. A PostScript program creates the BDN/XML file based on data from the SST file and PNG's.

Sorry if this is a stupid question.

The red background and B/W colors still show up when I use BDSup2Sub to view the BDN/XML file or the .sup file created with XML_PNG_to_SUP.bat. Am I doing something wrong, or is this normal? I don't want to view a BD with subtitle colors like this...
jd213 is offline   Reply With Quote
Old 24th December 2015, 04:10   #17  |  Link
Sm3n
Registered User
 
Join Date: Jul 2012
Posts: 94
Sorry for digging up but I tried your script it creates very cool sup. I don't really like the output colors.
I don't know where exactly change the color value. I want simply white sub with black border with no grey font. I know RGB and bbcode color but I don't know how to set transparency.
If anyone can read batch script an could help me it would be very sweet.
thx in advance. (I tested easySUP but the quality looks better with this technic)
Sm3n is offline   Reply With Quote
Reply


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 07:35.


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