all repos — videocr @ 8f8f2d6d79b316bf995910329c2dfcfcf1269d59

Extract hardcoded subtitles from videos using machine learning

videocr/api.py (view raw)

 1from . import utils
 2from .video import Video
 3
 4
 5def get_subtitles(
 6        video_path: str, lang='eng', time_start='0:00', time_end='',
 7        conf_threshold=65, sim_threshold=90, use_fullframe=False) -> str:
 8    utils.download_lang_data(lang)
 9
10    v = Video(video_path)
11    v.run_ocr(lang, time_start, time_end, conf_threshold, use_fullframe)
12    return v.get_subtitles(sim_threshold)
13
14
15def save_subtitles_to_file(
16        video_path: str, file_path='subtitle.srt', lang='eng',
17        time_start='0:00', time_end='', conf_threshold=65, sim_threshold=90,
18        use_fullframe=False) -> None:
19    with open(file_path, 'w+', encoding='utf-8') as f:
20        f.write(get_subtitles(
21            video_path, lang, time_start, time_end, conf_threshold,
22            sim_threshold, use_fullframe))