Recently, I have been working on a video hosting project and we are looking to translate around 5,000 video .mp4
files. I tried many GitHub projects, but none worked for .mp4
files only php or JSON files.
I need to translate the files from Google translate or whatever from English to French.
For example This is the video title.mp4 to Ceci est le titre de la video.mp4
CodePudding user response:
To get the filenames into python you can use the glob library to read them in so something like:
from glob import glob
import os
file_names = [os.path.basename(file) for file in glob(r`<FOLDER>\*.mp4`)]
translated_names = translate(file_names)
There are so many libraries that will help you translate that I will just pass over a tutorial and you can make up your own mind which one you want to use :)
https://towardsdatascience.com/language-translation-using-python-bd8020772ccc
CodePudding user response:
Here is how I tried to go about this.
Assuming you have the translate function
from google translate. Then get all the file names in your folder.
my_path = './video_files'
all_video_files = [f for f in listdir(my_path) if isfile(join(my_path, f))
and 'mp4' in f ]
Then read the contents and save them in a separate folder with the translated names like:
for file in all_video_files:
print(file)
file_translated = translate(file.split('.')[0])
with open(my_path f'/{file}', 'rb') as f:
contents = f.read()
with open(f'./translated_videos/{file_translated}.mp4', 'wb') as g:
g.write(contents)
g.close()
f.close()