Page 1 of 1

Subtitles in MediaCoder

Posted: Mon Aug 15, 2011 10:44 pm
by meRobs
[Updated 4 Feb 2014]

In its simplest form an audio/video media file contains the viewable information (video) in one section of the file (the video ‘stream’) and what you hear, the audio, in a second stream. The combining of these two streams into one file (container) is called multiplexing or muxing for short; and the reverse process (demuxing) is also possible, a topic considered in another Guide (viewtopic.php?f=17&t=10900).

The audio and video streams need to be synchronised and the overall media file is referred to as a Container. More complicated files may contain more than one audio stream and they may also contain subtitle streams that may be switched on to overlay text to what is viewed or switched off if not required. In these cases, during play, the user needs to select which audio is to be heard and what subtitle, if any, is to be seen ‘over’ the video.

Not all containers support multiple audio or subtitles. Examples that do, include MKV files and VOB files, the latter being the type present on a DVD. Of course, not all players allow selection of audio or subtitle! In that case, any desired subtitle would need to be burnt into the video stream so that it may be seen – it then becomes a permanent part of the video stream. This is called rendering and the results are often referred to as hardsubs (hard subtitles).

Often the subtitle info is supplied by a text file that is separate from the audio/video file (see Section III, below), for example, when associated with AVI files downloaded from the web. It is also possible to convert a subtitle text file into a separate subtitle stream, often referred to as softsubs (soft subtitles). This may be done for VOBs using an authoring program like Adobe Encore. Authoring is discussed in (viewtopic.php?f=17&t=8454&start=0). It may also be done for other file types, such as MKV (see Section IV, below).

This Guide is mainly concerned with the rendering of subtitles in MediaCoder, and once rendered, they cannot be removed, although, adding softsubs is also considered briefly in Section V. The guide was developed from tests done initially in build 5182 and later in 5392 and 5522.

Contents

Section I. Test Files and Test Method
Section II. Subtitle Streams in the Source File
Section III. Hard-Render an External Subtitle Text File
Section IV. Structure of Subtitle text file
Section V. Subtitles Output as a separate Stream

I. Test Files and Test Method

Subtitles are often found in DVDs and in Blu-ray discs. There, they are present as ‘sub-pictures’, i.e., in the form of images (groups of pixels) whose font and colour are fixed. Hence, the subtitles in files extracted or ripped from these discs, such as VOB files, cannot have their fonts or font colours changed.
Also, some audio/video files, such as AVI, MP4 and MKV, support the inclusion of text-based subtitle streams within them.

Hence, in studying how MediaCoder treats subtitles I considered six source files:
A: a VOB file containing 8 subtitle streams, as an example of image-based subtitles
B: an MKV file containing a single subtitle stream, presumably text-based
C: For use in Sections III and IV, a VOB, an MKV, an MP4 and an AVI file, each without an internal subtitle stream, created using the settings given in the Encoding Guide (viewtopic.php?f=17&t=9643 ). These were used in conjunction with a number of SRT, SUB and SSA text files created (Section IV) to serve as external subtitle files, when required.

Depending on the test, I tried a variety of Fonts, selected from the Drop-down menu on the Subtitle tab. In my case, with Windows 7, the fonts were merely those already listed under C:/ Windows > Fonts. I chose three that were easily distinguished from each other: ACaslonPro-Bold, Harlow Solid Italic and Old English Text MT. Also, in most cases, I left the subtitle ID at 0, the default.

Note that the Font colour does not appear to be selectable in MediaCoder. Certainly, the choice of Colour is not offered on the Subtitle tab (builds 4797 to 5522, at least) and, under Settings > Overall > Subtitles, the only colour choice relates to the background to the Font, and not the font itself. However, note the anomalous behaviour described in Section III and see Section V.

The tests for this Guide were done for a conversion to MP4 and/or to MKV. Their settings were established using Presets defined in the Encoding Guide (viewtopic.php?f=17&t=9643 ).

II. Subtitle Streams within the Source File

The ability of MediaCoder to hard-render the subtitle stream present within a source file, i.e., within its container, may be judged from the “Test Report” on MediaCoder builds. Up to and including build 5290 (viewtopic.php?f=17&t=10383 ) the reports refer to 32-bit (x86) builds and after build 5290, the Test Report (viewtopic.php?f=17&t=12306 ) refers to 64-bit builds. In both cases, the tests included the ability of MediaCoder to ‘Hard Render’ the subtitle stream of a VOB (file A in Section I), while encoding to MPEG2. Since build 5200, the test was expanded to include an MKV file (file B in Section I) and the conversion to MP4. Moreover, it was found that success may require the use of MEncoder as the video 'Source'.

Assuming your build of MediaCoder works in this regard, there are 3 things to consider.
(1) The render “Mode” on the Subtitle tab should be set at Text Render, A.S.S Render or VobSub Render for builds since 5335 or set “Renderer” at Default in earlier builds. This should result in the subtitle stream being Hard Rendered onto the video stream.
(2) Scale, Position, Outline and Font:these parameters, also on the Subtitle tab, had no effect on a subtitle from a VOB (file A) because it was image-based. However, for the above MKV file (file B), these parameters did affect the appearance of the hard-rendered, text-based subtitles. In all cases, the displayed text was white (in my case, at least).
(3) Then, you select the desired subtitle stream by setting the “ID” value on the subtitle tab. Unfortunately the subtitle streams are not displayed in the Properties panel of MediaCoder. To identify the stream IDs, you need to select the file and click F8 or Item > Details of Selected File (opens MediaInfo).

For example, the above VOB test file has 8 subtitle streams. In the player ‘VLC’ (R-click > Video > Subtitle) the streams are indicated as Track 1 to Track 8 and in MediaInfo as Text #1 to Text #8, as follows:
Text #1 had ID: 189 (0xBD)-32 (0x20) --- (the format for ID may be different in other types of file)
...
Text #4 had ID: 189 (0xBD)-35 (0x23) and
Text #8 had ID: 189 (0xBD)-41 (0x29).
Notice that the value after the “-” sign incremented through the series from 32 to 41, with two values missing (36 & 37). In this file, this value is the stream ID, since by setting ID on the Subtitle tab to 32, 33, 34, etc, I was able to get the different languages (streams).
The default value in MediaCoder is: "ID = 0”, which gave a result that matched that when the ID was set at 35, which may well be the default (?). You may need to test this option with your files.

III. Hard Render an External Subtitle Text File

Subtitles may also be created as separate text files (SRT, SUB or SSA) by a user (Section IV) or generated from image-based subtitle streams using OCR (Optical Character Recognition) software. If you need to hard-render subtitle text from such an external subtitle file into the video stream of an audio/video file, such as an MP4, you need to use the following steps.

The Procedure:
(1) Load the audio/video source file into MediaCoder.
(2) On the Subtitle tab, set “Mode” on the Subtitle tab to either ‘Text Render’ or ‘A.S.S Render’ for builds since 5335, with differing results (colour: see below). For earlier builds of MediaCoder, set “Renderer” equal to ‘Default’.
(3) Select the subtitle text file on the Subtitle tab via the browse button (“…”) beside the ‘Subtitle File’ panel. The SRT, SUB or SSA file need not be in the same folder as the source file nor does it need to have a similar name.
(4) Convert using suitable settings for video, audio and container, etc. For this guide, I chose to output as MP4 and/or MKV (Section I).

Change the Font, Scale, Position and Outline: I tried three different Fonts using the drop-down menu on the Subtitle tab and each worked. The Scale slider sets the size of the text font in pixels relative to the frame of the source (its resolution or ‘Resize’). The Position slider sets the location of the subtitle relative to the top of the video frame. For example, Position = 5 places the two-line text very close to the top and a value of 100 places it close to the bottom. Note that the default value is ‘0’, which is taken as the ‘maximum’, may lead to strange behaviour. For example, the default position, 0, places the text near the bottom, the value 1 or 2 places the text near the top, yet an intermediate value (0.5 say) fails to give an intermediate position! Best to leave it at the default or choose a value between 10 (near top) and 100 (bottom). Outline merely marks the outer edge of the displayed text in black, with a thickness varying between 0 and 8. Note that all four parameters are set quantitatively via Settings > Overall > Subtitles.

Change the Font Colour: the colour of text cannot be defined in an SRT or SUB file and cannot be directly set in MediaCoder. However, it can be affected indirectly! I found in build 5392, for example, that an external SRT file added to a VOB, MKV, MP4 or AVI (Section I), was hard-rendered in white for Mode = Text Render and yellow for A.S.S Render. Both ‘modes’ gave the font type as selected via its panel on the Subtitle tab, with Text Render giving a sensibly large font, whereas, A.S.S Render gave text that was roughly half the size (adjustable via ‘Scale’).

SSA text files do support font style and colour. Therefore, when hard-rendered using A.S.S Render as the “Mode”, the resultant subtitles have the colour set in the SSA file but with the font type set on the Subtitle tab. On the other hand, choosing Text Render as the Mode gives hard-rendered text in a white default font (Arial?).

Comment 1: initially, I tried rendering subtitle text with Copy Video selected on the video tab, but, this always failed. I realised immediately, that this makes sense. The reason? The subtitle text information needs to be written into the video frame data and this requires re-encoding.

Comment 2: an attempt to hard-render an external SRT file into a source file that also contains an internal subtitle stream may give results that differ from the above! There is confusing for MediaCoder. It needs to decide which to render, the internal stream or the external SRT? For example, in the case of a VOB source, the internal stream is rendered, as per Section II, for Mode = Text Render and the SRT file is rendered in for Mode = A.S.S Render, as above. The opposite outcome occurs for an MKV file with internal subtitle streams. It results in the SRT being rendered for Text Render (white) and the internal stream being rendered for A.S.S Render (yellow).

IV. Structure of a Subtitle File

In this guide I consider two common types of subtitle text-files, those with the extensions SRT and SUB. They are simple text files and, as far as I can tell, they are identical except for their differing extensions. For the above test, I prepared my own files using Notepad. I tried 3 forms, by saving the files via File > Save As and using ANSI, Unicode or UTF-8 for “Encoding”. All three forms worked in MediaCoder.

An SRT or SUB text file consists of a number of text groups, each representing lines of text to be displayed for a defined period of time, and when saved, given the SRT or SUB extension. Each text group is in the following form.
N
time1 --> time2
first line of text
second line of text
(space).
Where ‘N’ is the subtitle number and all the times are given in the format: hh:mm:ss,millisecond (see below). And especially note the comma before the millisecond values. The subtitle is to first appear at time1 and to turn off at time2.

SRT and SUB files are simple types with limited features. They may be created in Notepad, and do not carry parameters that define the size, type or colour of the font to be displayed (the “Font” setting in Notepad merely sets the appearance of the text in that App. More advanced forms of subtitle file are the SSA file and the A.S.S file, which are not considered here! There are tools available for converting SRT/SUB to SSA, etc.

An example of an SRT/SUB file is:
1
00:00:32,910 --> 00:00:38,064
The Title of this Movie

2
00:03:26,110 --> 00:03:29,420
Hi, my name is Fred and I
like talking to women.

3
00:00:11,544 --> 00:00:14,922
I am a woman and I don’t like talking.

4


An SSA text file may be created from one of the above using a program such as “Subtitle Workshop”, which is free. For this Guide I took an SRT file created as per above and converted it to an SSA with a green font in Monotype Corsiva to distinguish it. Finally, I removed its shadow in Notepad (set its value to 0).

V. Subtitles Output as a separate Stream

Up to and including build 5588, MediaCoder seems unable to copy over a subtitle stream from one file (container type) to another, as noted in the Topic: viewtopic.php?f=28&t=12993.

However, if you wish to create a subtitle stream within an output file/container from a separate, external subtitle text file, such as an SRT, SUB or SSA, then select “Subtitle Stream” as Mode on the Subtitle tab. This will not hard-render the subtitles but will add them as an internal stream alongside the audio and video streams. Of course, the chosen Container must support a text-based subtitle stream of the chosen type (MP4 will support SRT and SUB but not SSA).
As a test I took the 4 files listed under C in Section 1, and selected either an SRT or an SSA text file as the external source of subtitles and, in builds 5392 and 5522, I set Mode as Subtitle Stream on the Subtitle tab. Then, I converted to either MP4 or to MKV.

As a result, the SRT file became an internal stream (soft-subbed) in the default font, i.e., as a simple font (Arial?) in white. To see the stream, I used VLC as player and turned on the Subtitle track. On the other hand, the SSA file displayed text in the font style, colour, shadow and outline, etc, as defined in its file. But, only when converting to MKV, since MP4 doesn’t support a stream in SSA.

If you wish to insert the subtitles into DVD files, they need to be image-based and are best done using an Authoring application, such as Adobe Encore CS3 or the freebie: DVDstyler (see the Authoring Guide at: viewtopic.php?f=17&t=8454&start=0). Whereas, the positioning and colour of subtitles may be changed in DVDstyler, they may be modified later, if need be, as may the timing, by loading the VOB into DVDsubEdit.

Note 1: before merging a subtitle text file you may wish to see how it looks first and edit the actual text or the timing of individual subtitles. This can be done in “Subtitle Workshop”, which overlays the subtitles while playing the intended video file (loaded via Movie > Open), then saves to a subtitle file. It supports many subtitle formats, such as SRT (SubRip), SUB (SubViewer) and SSA (SubStation Alpha). Subtitle Workshop can create, edit or convert from one of many subtitle formats to another.

Re: Subtitles in MediaCoder

Posted: Mon Aug 15, 2011 10:48 pm
by meRobs
I have added the above post as a guide under Tips & Guides (link below).

If you have any comments or suggestions please PM me or write a Post in Basic Discussions.
Thanks