Workflow for multi-lingual subtitles in DVD Studio Pro

Despite reading manuals, a good deal of googling, and even attending Apple’s One to One tutoring for a year, I still haven’t read of a good solution for easily creating multi-lingual subtitles in DVD Studio Pro.

So I made one myself, and that’s what I’m presenting here. Feel free to use it, and let me know how you get on with a comment below. (Note that it uses AWK, so it’ll work straightaway on Linux and Mac, but you’ll need to install AWK or GAWK on Windows — google for it). Please do suggest possible improvements where you see them.

What I want to do:

  1. create start and stop points for subtitles using keystrokes while a video is playing
  2. import subtitle text from a separate file where it has been created/translated externally
  3. be able to easily add a new language to an existing subtitled project

And this is how I go about it. (I’ll do another post about other things I tried and why they didn’t work out, but here’s what I’ve found to work after numerous dead ends).

(1) Use Jubler to create the timings, either by using the method described in the first part of this article, or by following “How can I create new subtitles while the movie is played?” in the Jubler documentation.

You don’t need to type the text of the subtitles if you’ve already got it in another file, although I’ve found it useful to put in one or two key words that you can later match up to the spoken dialogue. The important thing at this stage is to get the start and end point of each subtitle in the right place. Save the result as a .stl file. For the purpose of these instructions, I’ll assume it’s called blank.stl — note that it MUST be in STL format for the AWK script below to work.

(2) Copy and paste the following AWK script into a new text file, and save it with the filename translateSTL.

#!/usr/bin/awk -f
# by Tim Morley, 2010
# distributed under Creative Commons Attribution-Share Alike license
# http://creativecommons.org/licenses/by-sa/2.0/uk/
#
# =====================================================================
#
# Syntax:
# ~$ translateSTL lang=XX start=ROW translations.csv file.stl
#
# where:
# - XX is a language code (e.g. EN, HU, DE, etc.) which must match
# a code in the top row of one column in translations.csv
# - ROW is the line number in translations.csv of the first subtitle
# which is to be imported
# - translations.csv is a TAB-separated (NOT comma-separated) file
# containing set(s) of translated subtitles (one subtitle per cell,
# one language per column). This file should contain at least as
# many subtitles as are contained in file.stl
# - file.stl is a subtitle file in STL format
#
# The function will send a copy of file.stl to STDOUT which retains the
# timecodes from file.stl but next to the subtitles from the relevant
# column of translations.csv
#
# =====================================================================

BEGIN { FS = "\t" } # separator in translations.csv is tab (not comma, to avoid problems with commas in subtitle text)

# var lang = language code set by user parameter
# var start = number of row where first translation to be used is found in translations.csv

((NR == FNR) && (NR == 1)) { # for first file ("translations.csv"), for first line
for (i=1; i<=NF; i++) {
if ($i == lang) langColumn = i; # find the column that matches the given language code
}
rowIndex = start; # set this once; can't put it in BEGIN {...}, because $start not yet instantiated there
}

((NR == FNR) && (NR >= start)) {
translation[NR] = $langColumn; # build array of translations using row numbers as indices
}

(NR != FNR) { # for second file ("file.stl")
FS = "[ \t]*,[ \t]*"; # setting FS here means first line of file.stl gets mangled if it starts with a timecode
if (FNR==1) printf "\xef\xbb\xbf" # add byte order mark, because DVD Studio Pro inexplicably needs it... grumble... you might be better to remove this line if you're not using DVD-SP
if ($1 ~ /^..:..:..:../) { # for each line that starts with a timecode...
printf "%s,%s, %s\n", $1, $2, translation[rowIndex]; # output its two timecodes followed by a translated subtitle
rowIndex++;
} else {
print $0; # otherwise just output the line as is
}
}


(3) Make the file you’ve just saved executable by opening a terminal window and typing:

chmod +x translateSTL

(4) Your translations need to be in a spreadsheet — Google Docs is a good option if you’re colaborating with other translators (although see comment below for one small problem, and how to get round it).

Sample spreadsheet showing translations in three languages

Each column should contain your subtitles in a different language, with one subtitle per spreadsheet cell. The top cell of each column (in Row 1) should contain the language code of that column (e.g. EO for Esperanto, EN for English, HU for Hungarian, etc.) And the file needs to be saved as a .csv file USING TABS, NOT COMMAS, TO SEPARATE THE FIELDS, and with NO QUOTATION MARKS AROUND THE TEXT, unless you want them to appear in your subtitles. The script above will not work if you do not use tabs as field separators.

For the purposes of these instructions, I’ll suppose that this file is called translations.csv

(5) To make things easy, put all the relevant files into the same folder: translateSTL, blank.stl and translations.csv. Now, if you want to merge the text from the English column of your translations.csv spreadsheet, starting from Row 2, into blank.stl to form a new file called EN.stl then back in the terminal window, cd to the folder where all these files are, and type the following incantation:

./translateSTL lang=EN start=2 translations.csv blank.stl > EN.stl

[The above should be all on one line; don’t press return until you’ve typed it all. Alternatively, you can copy and paste what’s above into your terminal, and then press return.]

If all has gone well, you should now have a new file called EN.stl containing the timestamps you created in Jubler together with the text from the column headed “EN” from your spreadsheet. (See comment below for potential problem with the first line of your new file, and how to fix it).

To create the German version, assuming you have a column headed DE in your spreadsheet, type this:

./translateSTL lang=DE start=2 translations.csv blank.stl > DE.stl

If you’re working on just one scene from the middle of a longer project, you can start to merge the text from a particular row of translations.csv. If your current scene starts at row 190 of translations.csv, type the following to create the French subtitles (from the column with FR in its first row) for this scene:

./translateSTL lang=FR start=190 translations.csv blank.stl > FR.stl

Hope that helps!

Advertisements

9 komentoj to “Workflow for multi-lingual subtitles in DVD Studio Pro”

  1. timsk Says:

    There are two small issues with the above:

    1. There’s one bug that I’m aware of but don’t know how to fix — if your STL file contains nothing before the first time code, the first line of the translated files gets mangled. 😦 To avoid the problem, just open up your “blank.stl” file as soon as you’ve saved it, and if the first line starts with a timecode, just insert a new first line above it, e.g.

    // This comment in the first line avoids problems with the translateSTL script

    2. Google Docs currently only gives the option of exporting a spreadsheet as .csv with commas separating the values, and with text surrounded by quotes. This won’t work with my script above (and believe me, I’ve tried to make it work). However, the collaborative aspect of a Google spreadsheet is still a powerful draw, when my co-workers all live in different countries, and the workaround is just one extra step — export the Google Spreadsheet in any format you like, then load it into your preferred spreadsheet application (OpenOffice.org will do nicely if you haven’t already got one — it’s free) then save it from there as a .csv file with the right settings. In OpenOffice.org, choose Save As… and choose the file type Text CSV (.csv), then tick the Edit filter settings box before clicking Save. In the Export of text files dialogue box, choose:
    • Character set: Unicode (UTF-8) <– unless you desperately need something different for your project
    • Field delimiter: {Tab}
    • Text delimiter: delete whatever is in here so that the field is blank
    And click OK.

  2. timsk Says:

    One other thing — I’ve mentioned DVD Studio Pro in the title, because that’s what I use for creating my DVDs, but in fact the workflow I’ve described is completely independent of DVD-SP. The STL files created using the method above can be imported into any software you like.

    However, if you are using DVD Studio Pro, you might find a free utility called Subtitle Xtractor useful. If you already have a DVD-SP project that has subtitles, and you want to add a new language, export your project as an “item description”, then use Subtitle Xtractor to extract an STL file from it. You can then use my script above to generate another STL file containing the same timestamps alongside your newly-translated subtitles, which can be re-imported into DVD Studio Pro.

  3. keen101 Says:

    I’ve never used DVD Studio Pro. I use Ubuntu Linux myself.

    The two programs i use are “AcidRip DVD Ripper”, and “Devede”. I just added subtitles to my first movie today. I used AcidRip to rip a copy of Gattaca to .AVI format, and then included the (already translated) Esperanto subtitle .STL file in the Devede program. Now i have a copy of Gattaca DVD with esperanto subtitles.

    Of course… AcidRip has an option to rip the english (or whatever) subtitles into an .STL file when Ripping it from a DVD. So, in theory you could rip subtitles, translate, and then re-encode into DVD .ISO format.

  4. timsk Says:

    Yet another comment on my own post — I’ve just started using this script in earnest on a proper project, and discovered that DVD Studio Pro seems to want a byte order mark in order to correctly interpret UTF-8 files. Grr.

    I’ve added a line to the script above:
    if (FNR==1) printf “\xef\xbb\xbf”
    but if you’re not using DVD Studio Pro, you can probably leave it out. In fact, the BOM is likely to confuse some other programs, so do delete that line unless you know that you need it.

  5. timsk Says:

    …aaaand yet another thing where DVD Studio Pro is overly-picky: I’ve suddenly got the error message “The video asset timecode may not correspond with the timecode specified” and I can’t import my subtitles.

    The solution is over on the Creative Cow forums but here’s the short version — import the subtitles before the video asset, and it works fine.

  6. Mafalda Says:

    I’ve just created the file “x translateSTL” in text editor with .txt extension. When typing the command in terminal, it delivers: “No such file or directory”

    What am I missing? Is it a problem with the extension or the folder where i save it?

    (3) Make the file you’ve just saved executable by opening a terminal window and typing:

    chmod +x translateSTL

  7. timsk Says:

    Hi Mafalda, and thanks for stopping by. Hope this helps you out with your project, and I’d be interested to hear whether it works well for you.

    As to your issue, the filename should be just “translateSTL” — the “x” isn’t part of the filename, and it shouldn’t have any extension either.

    You don’t say whether you’re using Windows, Linux, Mac or something else, but I’m guessing it’s Windows, and if that’s the case, you’ll need to do a few things differently:
    — you’ll need to put “awk.exe” into the folder you’re working in, and you can find it here:
    http://gnuwin32.sourceforge.net/downlinks/gawk-bin-zip.php
    — I *think* I’m right in saying that you can skip the “chmod +x translateSTL” line completely

    Let me know how you get on.

  8. Maite Says:

    Is there anyway to leave on the subtitles?? I mean that the person who sees the DVD dosen´t have to activete the subtitles? THANKS

  9. timsk Says:

    Yes, that’s certainly possible. You need to set the Disc Properties in the Disc Inspector (usually at the bottom right when you first open DVD Studio Pro). Under “Streams”, you choose the subtitle stream that you want to automatically display, then tick the “View” box. This will force the subtitle stream to be displayed by default when the DVD is inserted into a player.

    For more info, see page 552 of the manual (“Setting disc properties”).

    Hope that helps.

Respondi

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ŝanĝi )

Twitter picture

You are commenting using your Twitter account. Log Out / Ŝanĝi )

Facebook photo

You are commenting using your Facebook account. Log Out / Ŝanĝi )

Google+ photo

You are commenting using your Google+ account. Log Out / Ŝanĝi )

Connecting to %s


%d bloggers like this: