videocr/videocr/api.py

23 lines
791 B
Python
Raw Permalink Normal View History

2019-12-15 13:56:09 +01:00
from . import utils
2019-04-28 15:46:24 +02:00
from .video import Video
def get_subtitles(
video_path: str, lang='eng', time_start='0:00', time_end='',
conf_threshold=65, sim_threshold=90, use_fullframe=False) -> str:
2019-12-15 13:56:09 +01:00
utils.download_lang_data(lang)
2019-04-28 17:33:16 +02:00
2019-04-28 15:46:24 +02:00
v = Video(video_path)
v.run_ocr(lang, time_start, time_end, conf_threshold, use_fullframe)
return v.get_subtitles(sim_threshold)
2019-04-28 15:46:24 +02:00
def save_subtitles_to_file(
video_path: str, file_path='subtitle.srt', lang='eng',
time_start='0:00', time_end='', conf_threshold=65, sim_threshold=90,
use_fullframe=False) -> None:
2019-04-29 22:29:49 +02:00
with open(file_path, 'w+', encoding='utf-8') as f:
2019-04-28 15:46:24 +02:00
f.write(get_subtitles(
video_path, lang, time_start, time_end, conf_threshold,
sim_threshold, use_fullframe))