2019-12-15 13:56:09 +01:00
|
|
|
from . import utils
|
2019-04-28 15:46:24 +02:00
|
|
|
from .video import Video
|
|
|
|
|
|
|
|
|
2019-04-29 03:50:06 +02:00
|
|
|
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)
|
2019-04-29 03:05:02 +02:00
|
|
|
v.run_ocr(lang, time_start, time_end, conf_threshold, use_fullframe)
|
2019-04-29 03:50:06 +02:00
|
|
|
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',
|
2019-04-29 03:50:06 +02:00
|
|
|
time_start='0:00', time_end='', conf_threshold=65, sim_threshold=90,
|
2019-04-29 03:05:02 +02:00
|
|
|
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(
|
2019-04-29 03:05:02 +02:00
|
|
|
video_path, lang, time_start, time_end, conf_threshold,
|
2019-04-29 03:50:06 +02:00
|
|
|
sim_threshold, use_fullframe))
|