github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/video/subtitle/srt/doc.go (about)

     1  // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6  Package srt privades a parser for .SRT files, a widely used subtitle text file format.
     7  
     8  How To Use
     9  
    10  Example:
    11  
    12  	import (
    13  		"github.com/chai2010/gopkg/video/subtitle/srt"
    14  	)
    15  
    16  	func main() {
    17  		subtitles, err := srt.ParseData([]byte(srtText))
    18  		if err != nil {
    19  			log.Fatal(err)
    20  		}
    21  		...
    22  	}
    23  
    24  	const srtText = `
    25  	1
    26  	00:00:10,500 --> 00:00:13,000
    27  	Elephant's Dream
    28  
    29  	2
    30  	00:00:15,000 --> 00:00:18,000
    31  	At
    32  	`
    33  
    34  SubRip Text File Format
    35  
    36  The SubRip file format, as reported on the Matroska multimedia container format website,
    37  is "perhaps the most basic of all subtitle formats."
    38  SubRip (SubRip Text) files are named with the extension .srt,
    39  and contain formatted lines of plain text in groups separated by a blank line.
    40  Subtitles are numbered sequentially, starting at 1.
    41  The timecode format used is hours:minutes:seconds,milliseconds with time units fixed to two zero-padded digits and fractions fixed to three zero-padded digits (00:00:00,000).
    42  The fractional separator used is the comma, since the program was written in France.
    43  The subtitle separator, a blank line, is the double byte MS-DOS CR+LF pair,
    44  though the POSIX single byte linefeed is also well supported.
    45  
    46  	1. A numeric counter identifying each sequential subtitle
    47  	2. The time that the subtitle should appear on the screen, followed by --> and the time it should disappear
    48  	3. Subtitle text itself on one or more lines
    49  	4. A blank line containing no text, indicating the end of this subtitle
    50  
    51  
    52  SubRip (.srt) structure examples:
    53  
    54  	1
    55  	00:00:10,500 --> 00:00:13,000
    56  	Elephant's Dream
    57  
    58  	2
    59  	00:00:15,000 --> 00:00:18,000
    60  	At the left we can see...
    61  
    62  With specific positioning and styling:
    63  
    64  	1
    65  	00:00:10,500 --> 00:00:13,000 X1:63 X2:223 Y1:43 Y2:58
    66  	<i>Elephant's Dream</i>
    67  
    68  	2
    69  	00:00:15,000 --> 00:00:18,000 X1:53 X2:303 Y1:438 Y2:453
    70  	<font color="cyan">At the left we can see...</font>
    71  
    72  Formatting:
    73  
    74  Unofficially the format has very basic text formatting,
    75  which can be either interpreted or passed through for rendering depending on the processing application.
    76  Formatting is derived from HTML tags for bold, italic, underline and color:
    77  
    78  	- Bold – <b> ... </b> or {b} ... {/b}
    79  	- Italic – <i> ... </i> or {i} ... {/i}
    80  	- Underline – <u> ... </u> or {u} ... {/u}
    81  	- Font color – <font color="color name or #code"> ... </font> (as in HTML)
    82  
    83  Nested tags are allowed; some implementations prefer whole-line formatting only.
    84  
    85  See http://en.wikipedia.org/wiki/SubRip for more infomation.
    86  */
    87  package srt