webvtt-ruby

所属分类:collect
开发工具:Ruby
文件大小:0KB
下载次数:0
上传日期:2023-04-06 08:31:58
上 传 者sh-1993
说明:  WebVTT Ruby解析器和分段器,
(WebVTT Ruby parser and segmenter,)

文件列表:
Gemfile (95, 2023-04-06)
Gemfile.lock (199, 2023-04-06)
LICENSE (1069, 2023-04-06)
bin/ (0, 2023-04-06)
bin/webvtt-segmenter (1398, 2023-04-06)
lib/ (0, 2023-04-06)
lib/webvtt.rb (263, 2023-04-06)
lib/webvtt/ (0, 2023-04-06)
lib/webvtt/parser.rb (5004, 2023-04-06)
lib/webvtt/segmenter.rb (4195, 2023-04-06)
tests/ (0, 2023-04-06)
tests/parser.rb (7783, 2023-04-06)
tests/segmenter.rb (2607, 2023-04-06)
tests/subtitles/ (0, 2023-04-06)
tests/subtitles/big_srt.srt (68205, 2023-04-06)
tests/subtitles/big_srt.vtt (63808, 2023-04-06)
tests/subtitles/invalid_cue.srt (66, 2023-04-06)
tests/subtitles/invalid_cue.vtt (67, 2023-04-06)
tests/subtitles/no_text.vtt (78, 2023-04-06)
tests/subtitles/notvalid.vtt (91, 2023-04-06)
tests/subtitles/test.vtt (1867, 2023-04-06)
tests/subtitles/test_carriage_returns.vtt (1867, 2023-04-06)
tests/subtitles/test_from_srt.srt (108, 2023-04-06)
tests/subtitles/test_from_srt.vtt (115, 2023-04-06)
tests/subtitles/test_mmss_format.vtt (147, 2023-04-06)
tests/subtitles/test_multiple_line_separators.vtt (272, 2023-04-06)
tests/subtitles/weird_format.srt (183, 2023-04-06)
tests/subtitles/weird_format.vtt (193, 2023-04-06)
tests/subtitles/weird_format_corrected.vtt (193, 2023-04-06)
tests/subtitles/withnote.vtt (375, 2023-04-06)
webvtt-ruby.gemspec (678, 2023-04-06)

# WebVTT Ruby parser and segmenter The [WebVTT format](http://dev.w3.org/html5/webvtt/) is a standard captionning format used for HTML5 videos and HTTP Live Streaming (HLS). ## Installation Add this line to your application's Gemfile: gem 'webvtt-ruby' And then execute: $ bundle Or install it yourself as: $ gem install webvtt-ruby ## Usage To parse a webvtt file: ```ruby require "webvtt" webvtt = WebVTT.read("path/sub.vtt") webvtt.cues.each do |cue| puts "identifier: #{cue.identifier}" puts "Start: #{cue.start}" puts "End: #{cue.end}" puts "Style: #{cue.style.inspect}" puts "Text: #{cue.text}" puts "--" end ``` ## Converting from SRT You can also convert an SRT file to a standard WebVTT file: ```ruby webvtt = WebVTT.convert_from_srt("path/sub.srt", "path/sub.vtt") puts webvtt.to_webvtt ``` ## Segmenting for HTTP Live Streaming (HLS) Segmenting is required to work with HLS videos. ```ruby WebVTT.segment("subtitles/en.vtt", :length => 10, :output => "subtitles/en-%05d.vtt", :playlist => "subtitles/en.m3u8") ``` It will also generate the playlist in `m3u8`: ``` #EXTM3U #EXT-X-TARGETDURATION:17 #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD #EXTINF:13, en-00000.vtt #EXTINF:17, en-00001.vtt #EXTINF:12, en-00002.vtt #EXT-X-ENDLIST ``` To use the segmented webvtt files with your HLS playlist: ``` #EXTM3U #EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI="subtitles/en.m3u8" #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=300000,SUBTITLES="subs" demo-300000.m3u8 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=600000,SUBTITLES="subs" demo-600000.m3u8 ``` ## CLI You can also segment webvtt files using the command line `webvtt-segmenter`: ``` $ webvtt-segmenter -i subtitles/en.vtt -t 10 -m subtitles/en.m3u8 -o "subtitles/en-%05d.vtt" ``` ``` $ webvtt-segmenter -h Usage: bin/webvtt-segmenter [--arg] -i, --input [PATH] WebVTT or SRT file -b, --base-url [URL] Base URL -t, --target-duration [DUR] Duration of each segments. Default: 10 -o, --output [PATH] Path where WebVTT segments will be saved. Default: fileSequence-%05d.vtt -m, --playlist [PATH] Path where the playlist in m3u8 will be saved. Default: prog_index.m3u8 ``` ## Note `webvtt-ruby` was written in a few hours because there was no open source tool to segment webvtt files. It's not perfect at all but it does the job. ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request ## Author **Bruno Celeste** * http://coconut.co * bruno@coconut.co * [@brunoceleste](http://twitter.com/brunoceleste)

近期下载者

相关文件


收藏者