Transmission Subtitle Tutorial in Drupal

From Transmission
Jump to: navigation, search

Transmission Tutorial: overlaying subtitles in JW player

The aim is to get subtitle files to display over a video using JW player, and to be able to add translations so that the same video can be viewed with subtitle files of different languages. Thanks to Ben from for the heads up on how to do this.

Required modules

Installing JW player

You can download a zip of the files you need to put on your server here.

Tick the viral plug-in if you want to see the same file for the player that we use in this step by step guide. The viral plug in

Subtitles drupal 8.png

Unzip the files and make sure the place the player in your modules directory, here.


Create Content Type

You need set up a content type with 2 CCK fields one for the Video (which could be text or Embfield Media Field) - and another for Subtitle files (text). There are a few different possiblities for how to do this. You could set up a simple text field, in this way you could paste in the URL of the files. This would be useful if you were linking to external videos to save bandwidth for example. Although it's harder to set up the system to do it for the subtitle files.

In this example we'll set up a content type with video file and subtitle files uploaded via the CCK file field module.

To do this first create a new content type. Navigate to Administer » Content management » Content types /admin/content/types/add

Then enter the following data.

Subtitles drupal 1.png

Then we'll add field for the video file

Subtitles drupal 2.png

On the following screen you can leave it unchanged and press submit, we don't need to do anything special here. The size of the text field only needs to be as long as the URL.

Then add a field for the subtitle file.

Subtitles drupal 3.png

Again the following page where you set the defaults doesn't need to be changed.

Your settings should look something like this.

Subtitles2 drupal 1.png

Changing content template for the Content type

There are various ways this can be done we are going to use the Contemplate module as it's a quick way of doing it. You might want to build your own template files as a long term solution. It'll acheive the same ends.

Got the the Administer menu and click on Content > Content Templates

Next to the content type you created click create template.

Select the Body and input the variables coming in from the video and subtitle fields you created. You do this by finding a suiteable reference in the variable box, and clicking on the link (the name of the variable) and this imports the variable into the body box. See below examples.

Next you need to incorporate these variable in a Player. We are using the JW player, you can use this code as a template.

<script type="text/javascript">
  var sa = new SWFObject('/sites/all/modules/swftools/shared/flash_media_player/player-viral.swf

There are many different ways to do this. For my example I used filefield module to upload the flv file and the srt files. You can then use the filepath of the file field you created. print $node->field_subtitlefile2[0]['filepath'] in the Body of you Content Template set up. This is a working example of the content of a contemplate Body.

<div id="video-player" align="center"><object id="flashvideo"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="450" height="337"
<param name="movie" value="/sites/all/modules/swftools/shared/flash_media_player/player-viral.swf" />
<param name="wmode" value="window" />
<param name="allowfullscreen" value="true" />
<param name="FlashVars" value="file=<?php print $node->field_videosub2[0]['filepath'] ?>
&rotatetime=3&autostart=true&plugins=captions-1&captions.file=<?php print $node->field_subtitlefile2[0]['filepath'] ?>" />
<param name="quality" value="high" />
<embed name="flashvideo" allowScriptAccess="always"
 width="450" height="337" border="0" type="application/x-shockwave-flash"
pluginspage="" wmode="window"
allowfullscreen="true" quality="high" flashvars="file=<?php print $node->field_videosub2[0]['filepath'] ?>
&rotatetime=3&autostart=true&plugins=captions-1&captions.file=<?php print $node->field_subtitlefile2[0]['filepath'] ?>" />
<?php print $node->content['body']['#value'] ?>


There different aspects to doing translation for Drupal sites. What we need to do is to create a different version of the node for each language. Luckily in Drupal 6 there are good tools for this. To set up the content translation here's the process.

Install following modules

  • i18n
  • content translation

There is detailed help elsewhere for installing language support but here is a brief summary of some of the things you need to enable short form.

Change content type workflow settings

Once you have installed the following modules then make sure you change the following settings in your Content Type settings

Workflow settings > Enabled, with translation

Subtitles drupal 9.png

Add Languages

At the language page use the Add Lanuage tab to add the languages you need to your site Administer » Site configuration >> Language /admin/settings/language

Your page might end up looking a bit like this

Languages drupal 1.png

On the Configure tab of the languages settings page you need to change the value in Language negotiation to Path prefix with language fallback

Languages drupal 2.png

Adding a new Video and Subtitle data and choosing your language

To add the inicial video and subtitle file click on Add Content in your drupal menu - /node/add .

Select the Content type that has been set up to take Video and subtitle files. In this case it's named Video with subtitles

Languages drupal 7.png

Then in your upload form, in the relevant fields, add metadata, upload your video and subtitle files.

Make sure to select a language as well.

Languages drupal 3.png

Click on Save. You should see a page with your published video.

Notes: Your site may be set up in a different way, as if you have a link to the Video file (often in an flv format) then you could set up a simple text feed to link to that video file rather than uploading it.

File formats

Video: Your video file should be an flv for this installation to make it easy to stream.

Subtitle: Your subtitle file should be a in a time coded xml format, or a *.srt format also called SubRip. The file format is a TT Timed Text format. If you need to be able to create this files you may need to use a conversion tool like Subtitle Horse.

You can use these files to test it if you need to. You will need to download the subtitle file and install it on your own site as the JW player will only play subtitle files which are on the same server as it.

Now when you create your content you need to choose the language from the drop down list next to Language. If you don't do that then the Translate tab won't appear when you have submitted your content, and you won't be able to translate it easily.

Also there is the matter of permissions as well. You need to decide what user roles can edit these videos. You may want to set up a Translator role who are allowed to edit all the relevant CCK field you've created and to edit the Content type you've created for this video content type. You may want to look at help on permissions elsewhere.

Ideally if your permissions are set up correctly your logged in translators should see a tab to Wiew, Edit or Translate at the top of the content page.

Languages drupal 4.png

When clicking on Translate you'll see a list of languages and the option to translate languages that haven't been translated yet.

Languages drupal 5.png

When you click on Add Translation you go to a page where you can edit the new page that been created. Then you can remove the existing subtitle file and upload a new one of the appropriate language.

Languages drupal 6.png

Example: Site showing mulingual subtitle support working on Drupal

As part of Drupal_Transmission_Sprint_2009_uk#Subtitles_-_Documentation_and_the_future the site below was set up to show multilungual subtitles in action

| Subtitles in Drupal in Action

This page shows an example of using the contemplate module to take a link to a subtitle file and a video file (stored as cck fields in the node) and plug the information from these fields in JWPlayer

Using the Core Drupal Translation Module, copies of the original file links and info can then be made and then altered (alternative subtitles links, alternative video link with different audio dub, translated description) for each language selected by this module

There is some more information on TT subtitles and how they work with players here.