webvtt-py
is a Python library for reading, writing and converting WebVTT caption files. It also features caption segmentation useful when captioning HLS videos.
Documentation is available at http://webvtt-py.readthedocs.io.
$ pip install webvtt-py
import webvtt
for caption in webvtt.read('captions.vtt'):
print(caption.identifier) # cue identifier if any
print(caption.start) # cue start time
print(caption.end) # cue end time
print(caption.text) # cue payload
print(caption.voice) # cue voice span if any
import webvtt
webvtt.segment('captions.vtt', 'output/path')
Supported formats:
- SubRip (.srt)
- YouTube SBV (.sbv)
import webvtt
webvtt = webvtt.from_srt('captions.srt')
webvtt.save()
# alternatively in a single line
webvtt.from_sbv('captions.sbv').save()
Caption segmentation is also available from the command line:
$ webvtt segment captions.vtt --output output/path
Licensed under the MIT License.