[英]How can I translate multiple .mp4 video Titles at once in a folder?
最近,我一直在從事一個視頻托管項目,我們希望翻譯大約 5,000 個視頻.mp4
文件。 我嘗試了許多 GitHub 項目,但沒有一個適用於.mp4
文件,僅適用於 php 或 JSON 文件。
我需要將文件從谷歌翻譯或從英語翻譯成法語。
例如,這是 Ceci est le titre de la video.mp4 的視頻 title.mp4
要將文件名放入 python 中,您可以使用glob庫來讀取它們,如下所示:
from glob import glob
import os
file_names = [os.path.basename(file) for file in glob(r`<FOLDER>\*.mp4`)]
translated_names = translate(file_names)
有很多庫可以幫助您翻譯,我將通過一個教程,您可以自己決定要使用哪個:)
https://towardsdatascience.com/language-translation-using-python-bd8020772ccc
這是我嘗試 go 的方法。 假設您有來自谷歌翻譯的translate function
。 然后獲取文件夾中的所有文件名。
my_path = './video_files'
all_video_files = [f for f in listdir(my_path) if isfile(join(my_path, f))
and 'mp4' in f ]
然后閱讀內容並將它們保存在一個單獨的文件夾中,並帶有翻譯后的名稱,例如:
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.