webvtt-py
is a Python module for reading/writing WebVTT caption files. It also features caption segmentation useful when captioning HLS videos.
Requires Python 3.3+.
Documentation is available at http://webvtt-py.readthedocs.io.
$ pip install webvtt-py
from webvtt import WebVTT
for caption in WebVTT().read('captions.vtt'):
print(caption.start)
print(caption.end)
print(caption.text)
from webvtt import WebVTTSegmenter
WebVTTSegmenter().segment('captions.vtt', 'output/path')
Supported formats:
- SubRip (.srt)
- YouTube SBV (.sbv)
from webvtt import WebVTT
webvtt = WebVTT().from_srt('captions.srt')
webvtt.save()
# we can convert captions in one line
WebVTT().from_sbv('captions.sbv').save()
Caption segmentation is also available from the command line:
$ webvtt segment captions.vtt --output destination/directoy
Licensed under the MIT License.