Conversion_Kitchen_Code/kitchen_counter/conversion/subtitling/burn.py

228 lines
5.8 KiB
Python
Executable File

import sys
import os
from moviepy.editor import *
from .burn1 import Subtitling_Burn
from .base import make_directory
import random
# ppt = sys.argv[1]
# doc = sys.argv[2]
basepath = "/home/user/mnf/project/MNF/conversion/subtitling"
def burn_subtitle(mp4, lang_code, sub):
# lang = {
# 'Arabic': 'ar',
# 'Bengali': 'bn',
# 'Catalan': 'ca',
# 'English': 'en',
# 'French': 'fr',
# 'Gujarati': 'gr',
# 'Hindi': 'hi',
# 'Kannada': 'kn',
# 'Marathi': 'mr',
# 'Spanish': 'es',
# 'Tamil': 'ta',
# 'Telugu': 'te'
# }
lang = {
"Hindi": "hi",
"English": "en",
"Urdu": "ur",
"Arabic": "ar",
"Bengali": "bn",
"Kannada": "kn",
"Tamil": "ta",
"Bulgarian": "bg",
"Bangla": "bn",
"Malayalam": "ml",
"Russian": "ru",
"Serbian": "sr",
"Ukranian": "uk",
"Croatian": "hr",
"Irish": "ga",
"Albanian": "sq",
"Marathi": "mr",
"Persian": "fa",
"Telugu": "te",
"Turkish": "tr",
"Hungarian": "hu",
"Italian": "it",
"Romanian": "ro",
"Punjabi": "pa",
"Gujrati": "gu",
"Odia": "or",
"Chinese": "zh",
"Nepali": "ne",
"French": "fr",
"Spanish": "es",
"Indonesian": "id",
"Greek": "el",
"ja": "Japanese",
"Javanese": "jv",
"Korean": "ko",
"Belarusian": "be",
"Uzbek": "uz",
"Sindhi": "sd",
"Afrikaans": "af",
"German": "de",
"Icelandic": "is",
"Igbo": "ig",
"Latin": "la",
"Portugese": "pt",
"Myanmar": "my",
"Thai": "th",
"Sundanese": "su",
"lo": "Lao",
"amharic": "am",
"Sinhala": "si",
"Azerbaijani": "az",
"Kazak": "kk",
"Macedonian": "mk",
"Bosnian": "bs",
"Pashto": "ps",
"Malagasy": "mg",
"Malay": "ms",
"Yoruba": "yo",
"Czech": "cs",
"Danish": "da",
"Dutch": "nl",
"Tagalog": "tl",
"Norwegian": "no",
"Slovenian": "sl",
" Swedish": "sv",
"Vietnamese": "vi",
"Welsh": "cy",
"Hebrew": "he",
"Armenian": "hy",
"Khmer": "km",
"Georgian": "ka",
"Mongolian": "mn",
"Kurdish": "ku",
"Kyrgyz": "ky",
"Turkmen": "tk",
"Finnish": "fi",
"Haitian Creole": "ht",
"Hawaiian": "haw",
"Lithuanian": "lt",
"Luxembourgish": "lb",
"Maltese": "mt",
"Polish": "pl",
"Esperanto": "eo",
"Tatar": "tt",
"Uyghur": "ug",
"Hausa": "ha",
"Somali": "so",
"Swahili": "sw",
"Yiddish": "yi",
"Basque": "eu",
"Catalan": "ca",
"Cebuano": "ceb",
"Corsican": "co",
"Estonian": "et",
"Frisian": "fy",
"Galician": "gl",
"Hmong": "hmn",
"Kinyarwanda": "rw",
"Latvian": "lv",
"Maori": "mi",
"Samoan": "sm",
"Scots Gaelic": "gd",
"Sesotho": "st",
"Shona": "sn",
"Slovak": "sk",
"Xhosa": "xh",
"Zulu": "zu",
}
lang_code = lang[lang_code]
movie_name = os.path.splitext(mp4)[0]
vid_path = make_directory(movie_name)
clip = VideoFileClip(mp4)
clip = clip.subclip(0, 5)
value = clip.size[0]
print("Ready to hardburn subtitles")
# for i in sub:
# print(sub)
# sub = sub[27:]
# exit()
# /home/user/mnf/project/MNF/media/videos/Subtitling_Videos/overlay/google_subtitle.srt
obj = Subtitling_Burn(mp4, sub)
burn_path = obj.burnSRT(lang_code, vid_path, value)
return str(burn_path)
# os.system("python burn1.py " + mp4 + " " +
# i + " " + lang_code + " " + folder)
print("-" * 30)
# print("Ready to embed subtitles")
# os.system("ffmpeg -i " + mp4 + " -i " + i +
# " -c copy -c:s mov_text " + output)
# os.system("ffmpeg -i " + mp4 + " -i " + sub_file +
# " -c copy -c:s mov_text " + final)
# os.system("ffmpeg -i " + mp4 + " -i " + sub_file + " -c:v copy -c:a copy -c:s mov_text -map 0:v -map 0:a -map 1 -map 2 -metadata:s:s:0 language=kor -metadata:s:s:1 language=eng " + final)
# mp4 = sys.argv[1]
# language_code = sys.argv[2]
# srt = sys.argv[3]
# folder = os.path.splitext(mp4)[0]
# current = basepath + "/" + folder
# final = folder + "_overlay.mp4"
# srt = []
# total arguments
# n = len(sys.argv)
# text = ''
# for i in range(3, n):
# srt.append(sys.argv[i])
# text = text + current + "/" + str(sys.argv[i])+"\n"
# with open(rf"{current}/sub.txt", "w") as file_object:
# # Append 'hello' at the end of file
# file_object.write(text)
# sub_file = current+"/sub.txt"
# burn_subtitle(mp4, language_code, srt)
def overlay(mp4, sub):
print("Ready to overlay subtitles")
movie_name = os.path.splitext(mp4)[0]
vid_path = make_directory(movie_name)
num = random.randint(0, 1000)
srt_path = ""
for i in sub:
srt_path += " -i " + i[0]
mapstr = ""
lang = ""
for i in range(len(sub)):
mapstr += " -map " + str(i + 1)
lang += " -metadata:s:s:" + str(i) + " language=" + sub[i][1]
cmd = (
f"ffmpeg -i {mp4}"
+ srt_path
+ " -c:v copy -c:a copy -c:s mov_text -map 0:v -map 0:a"
+ mapstr
+ lang
+ " "
+ vid_path
+ "/overlay_"
+ str(num)
+ ".mp4"
)
print(cmd)
os.system(cmd)
file_path = vid_path + "/overlay_" + str(num) + ".mp4"
return str(file_path)