multilang-asr-captioner / utils /process_video.py
marquesafonso's picture
move transcriber to hf spaces. edit requirements. add logger (wip).
9876d02
raw
history blame
1.58 kB
from utils.transcriber import transcriber
from utils.subtitler import subtitler
import logging, os
# Set up logging
logging.basicConfig(filename='main.log',
encoding='utf-8',
level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
# API Function
def process_video(invideo_filename:str,
srt_path: str,
task: str,
max_words_per_line:int,
fontsize:str,
font:str,
bg_color:str,
text_color:str,
caption_mode:str,
config_file:str
):
invideo_filename = os.path.normpath(invideo_filename)
invideo_path_parts = invideo_filename.split(os.path.sep)
VIDEO_NAME = invideo_path_parts[-1]
OUTVIDEO_PATH = os.path.join(invideo_path_parts[-3], invideo_path_parts[-2], f"result_{VIDEO_NAME}")
if srt_path:
subtitler(invideo_filename, srt_path, OUTVIDEO_PATH, fontsize, font, bg_color, text_color, caption_mode)
return OUTVIDEO_PATH, srt_path
SRT_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.srt")
logging.info("Transcribing...")
if not os.path.exists(SRT_PATH):
transcriber(invideo_filename, SRT_PATH, max_words_per_line, task, config_file)
logging.info("Subtitling...")
subtitler(invideo_filename, SRT_PATH, OUTVIDEO_PATH, fontsize, font, bg_color, text_color, caption_mode)
return OUTVIDEO_PATH, SRT_PATH