# from .burn import burn_subtitle # import cv2 from moviepy.editor import * # import pandas as pd # import pysrt from moviepy.video.tools.subtitles import SubtitlesClip import sys import os import random basepath = "/home/user/mnf/project/MNF/conversion/subtitling" class Subtitling_Burn: def __init__(self, video_path, srt_path): self.video_path = video_path self.srt_path = srt_path print(self.srt_path) # def PreprocessSRT(self): # srt_data = pysrt.open(self.srt_path) # print(srt_data) # subs = [] # for i in srt_data: # if i.start.minutes == 0: # text = i.text # start = i.start.seconds # end = i.end.seconds # subs.append(((start, end), text)) # else: # text = i.text # start_s = i.start.seconds # start_m = i.start.minutes # start = start_m + start_s/60 # end_s = i.end.seconds # end_m = i.end.minutes # end = end_m + end_s/60 # subs.append(((start, end), text)) # print(subs) # return subs def burnSRT(self, language_code, curr, value): num = random.randint(0, 1000) # subs = self.PreprocessSRT() font_dictionary = { "hi": "Samyak-Devanagari", "en": "Arial", "ur": "Arial", "ar": "Arial", "bn": "Lohit-Bengali", "kn": "Lohit-Kannada", "ta": "Lohit-Tamil", "bg": "Arial", "ml": "Lohit-Malayalam", "ru": "Arial", "sr": "Arial", "uk": "Arial", "hr": "Arial", "ga": "Arial", "sq": "Arial", "mr": "Lohit-Devanagari", "fa": "KacstFarsi", "te": "Lohit-Telugu", "tr": "Arial", "hu": "Arial", "it": "Arial", "ro": "Arial", "pa": "Arial", "gu": "Lohit- Gujarati", "or": "Lohit-Odia", "zh": "Arial", "ne": "Arial", "fr": "Arial", "es": "Arial", "id": "Arial", "el": "Arial", "ja": "Arial", "jv": "Arial", "ko": "Un-Batang", "be": "Arial", "uz": "Arial", "sd": "Arial", "af": "Arial", "de": "Arial", "is": "Arial", "ig": "Arial", "la": "Arial", "pt": "Arial", "my": "Arial", "th": "Arial", "su": "Arial", "lo": "Arial", "am": "Arial", "si": "Arial", "az": "Arial", "kk": "Arial", "mk": "Arial", "bs": "Arial", "ps": "KacstFarsi", "mg": "Arial", "ms": "Arial", "yo": "Arial", "cs": "Arial", "da": "Arial", "nl": "Arial", "tl": "Arial", "no": "Arial", "sl": "Arial", "sv": "Arial", "vi": "Arial", "cy": "Arial", "he": "Arial", "hy": "Arial", "km": "Khmer-OS", "ka": "Arial", "mn": "Arial", "ku": "Arial", "ky": "Arial", "tk": "Arial", "fi": "Arial", "ht": "Arial", "haw": "Arial", "lt": "Arial", "lb": "Arial", "mt": "Arial", "pl": "Arial", "eo": "Arial", "tt": "Arial", "ug": "Arial", "ha": "Arial", "so": "Arial", "sw": "Arial", "yi": "Arial", "eu": "Arial", "ca": "Arial", "ceb": "Arial", "co": "Arial", "et": "Arial", "fy": "Arial", "gl": "Arial", "hmn": "Arial", "rw": "Arial", "lv": "Arial", "mi": "Arial", "sm": "Arial", "gd": "Arial", "st": "Arial", "sn": "Arial", "sk": "Arial", "xh": "Arial", "zu": "Arial", } font = font_dictionary[language_code] if value > 0 and value < 300: fontsize = 10 elif value > 301 and value < 600: fontsize = 20 elif value > 601 and value < 900: fontsize = 30 elif value > 901 and value < 1200: fontsize = 40 else: fontsize = 50 def generator(txt): return TextClip(txt, font=font, fontsize=fontsize, color="white") subtitles = SubtitlesClip(self.srt_path, generator) temp_audio = "/home/user/mnf/project/MNF/Aman/temp-audio.m4a" video = VideoFileClip(self.video_path) result = CompositeVideoClip( [video, subtitles.set_pos(("center", "bottom"))]) print("$" * 50) print(curr) print("$" * 50) result.write_videofile( "/home/user/mnf/project/MNF/Aman/hardburn_100.mp4", fps=video.fps, temp_audiofile=temp_audio, remove_temp=True, codec="vp9", audio_codec="aac", ) if __name__ == "__main__": video_path = "/home/user/mnf/project/MNF/Aman/paint_it_black.mp4" srt_path = "/home/user/mnf/project/MNF/Aman/hindi.srt" # video_path = sys.argv[1] # srt_path = sys.argv[2] # srt = os.path.splitext(srt_path)[0] # print(srt) # language_code = sys.argv[3] # movie_name = sys.argv[4] # current = basepath + "/" + movie_name # obj = Subtitling_Burn(video_path, srt_path) # obj.burnSRT('hi', '/home/user/mnf/project/MNF/Aman/', 400) # temp_audio= rf'{currentDirectory}/{self.script_name}/video/abc.ogg' # video_with_new_audio = video.set_audio(AudioFileClip( # rf'{currentDirectory}/{self.script_name}/{scene_mp3}.mp3')) # video_with_new_audio.write_videofile( # rf'{currentDirectory}/{self.script_name}/video/{scene_mp3}.webm', fps=10,codec='libvpx', temp_audiofile=temp_audio) # clips.clear()