2017年3月30日 星期四

webvtt format

https://dev.opera.com/articles/zh-cn/an-introduction-to-webvtt-and-track/

https://developer.mozilla.org/zh-TW/docs/Web/API/Web_Video_Text_Tracks_Format


時間標籤
  • 時間標籤中的時間,必須比該節點的開始時間晚、比同節點先前之其他時間標籤晚,並且早於該節點的結束時間。 當前文字(active text) 代表此時間標籤到下個時間標籤(或文字內容的結尾)之間的文字,其他同節點中,比 當前文字 早的文字都稱為 先前文字(previous text) ,而晚於 當前文字 的便稱為 未來文字(future text) 。如此便可做出卡拉OK字幕效果
Example 12 - Karaoke style text
1
00:16.500 --> 00:18.500
When the moon <00:17.500>hits your eye

1
00:00:18.500 --> 00:00:20.500
Like a <00:19.000>big-a <00:19.500>pizza <00:20.000>pie

1
00:00:20.500 --> 00:00:21.500
That's <00:00:21.000>amore


When this specification says that a user agent is to collect a WebVTT timestamp, the user agent must run the following steps:
  1. Let input and position be the same variables as those of the same name in the algorithm that invoked these steps.
  2. Let most significant units be minutes.
  3. If position is past the end of input, return an error and abort these steps.
  4. If the character indicated by position is not an ASCII digit, then return an error and abort these steps.
  5. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
  6. Interpret string as a base-ten integer. Let value1 be that integer.
  7. If string is not exactly two characters in length, or if value1 is greater than 59, let most significant units be hours.
  8. If position is beyond the end of input or if the character at position is not a U+003A COLON character (:), then return an error and abort these steps. Otherwise, move position forwards one character.
  9. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
  10. If string is not exactly two characters in length, return an error and abort these steps.
  11. Interpret string as a base-ten integer. Let value2 be that integer.
  12. If most significant units is hours, or if position is not beyond the end of input and the character at position is a U+003A COLON character (:), run these substeps:
    1. If position is beyond the end of input or if the character at position is not a U+003A COLON character (:), then return an error and abort these steps. Otherwise, move position forwards one character.
    2. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
    3. If string is not exactly two characters in length, return an error and abort these steps.
    4. Interpret string as a base-ten integer. Let value3 be that integer.
    Otherwise (if most significant units is not hours, and either position is beyond the end of input, or the character at position is not a U+003A COLON character (:)), let value3 have the value of value2, then value2have the value of value1, then let value1 equal zero.
  13. If position is beyond the end of input or if the character at position is not a U+002E FULL STOP character (.), then return an error and abort these steps. Otherwise, move position forwards one character.
  14. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
  15. If string is not exactly three characters in length, return an error and abort these steps.
  16. Interpret string as a base-ten integer. Let value4 be that integer.
  17. If value2 is greater than 59 or if value3 is greater than 59, return an error and abort these steps.
  18. Let result be value1×60×60 + value2×60 + value3 + value4∕1000.
  19. Return result.






https://www.w3.org/community/texttracks/2013/09/11/carriage-of-webvtt-and-ttml-in-mp4-files/


By default, the line is set to auto.




A line
The line defines positioning of the cue box.
The line offsets the cue box from the top, the right or left of the video viewport as defined by the writing direction, the snap-to-lines flag, or the lines occupied by any other showing tracks.
The line is set either as a number of lines, a percentage of the video viewport height or width, or as the special value auto, which means the offset is to depend on the other showing tracks.
By default, the line is set to auto.
If the writing direction is horizontal, then the line percentages are relative to the height of the video, otherwise to the width of the video.
WebVTT cue has a computed line whose value is that returned by the following algorithm, which is defined in terms of the other aspects of the cue:
  1. If the line is numeric, the WebVTT cue snap-to-lines flag of the WebVTT cue is false, and the line is negative or greater than 100, then return 100 and abort these steps.
    Although the WebVTT parser will not set the line to a number outside the range 0..100 and also set the WebVTT cue snap-to-lines flag to false, this can happen when using the DOM API’s snapToLines and line attributes.
  2. If the line is numeric, return the value of the WebVTT cue line and abort these steps. (Either the WebVTT cue snap-to-lines flag is true, so any value, not just those in the range 0..100, is valid, or the value is in the range 0..100 and is thus valid regardless of the value of that flag.)
  3. If the WebVTT cue snap-to-lines flag of the WebVTT cue is false, return the value 100 and abort these steps. (The line is the special value auto.)
  4. Let cue be the WebVTT cue.
  5. If cue is not in a list of cues of a text track, or if that text track is not in the list of text tracks of a media element, return −1 and abort these steps.
  6. Let track be the text track whose list of cues the cue is in.
  7. Let n be the number of text tracks whose text track mode is showing and that are in the media element’s list of text tracks before track.
  8. Increment n by one.
  9. Negate n.
  10. Return n.






A line alignment
An alignment for the cue box’s line, one of:
Start alignment
The cue box’s top side (for horizontal cues), left side (for vertical growing right), or right side (for vertical growing left) is aligned at the line.
Center alignment
The cue box is centered at the line.
End alignment
The cue box’s bottom side (for horizontal cues), right side (for vertical growing right), or left side (for vertical growing left) is aligned at the line.
By default, the line alignment is set to start.
The line alignment is separate from the text alignment — right-to-left vs. left-to-right cue text does not affect the line alignment.