Я плохо разбираюсь в Python, но мне нужно было научиться комбинировать видео с субтитрами, не полагаясь на онлайн-сервисы. Я нашел простой код в Интернете, но он не работает должным образом. Вот код, который я использовал: < /p>
import imageio
import pysrt
import sys
import os
from moviepy.editor import *
video = VideoFileClip("C:\\yt-dlp\\PC Engine Emulator Full Setup Guide [Ares].webm")
subtitles = pysrt.open("C:\\yt-dlp\\PC Engine Emulator Full Setup Guide [Ares].srt", encoding='utf-8')
subtitle_clips = []
for subtitle in subtitles:
text = subtitle.text
start_time = subtitle.start.seconds + subtitle.start.milliseconds / 1000.0
end_time = subtitle.end.seconds + subtitle.end.milliseconds / 1000.0
duration = end_time - start_time
text_clip = TextClip(text, fontsize=24, color='white', font="Arial")
text_clip = text_clip.set_position(('center', 'bottom')).set_start(start_time).set_duration(duration)
subtitle_clips.append(text_clip)
final_video = CompositeVideoClip([video] + subtitle_clips)
final_video.write_videofile('C:\\yt-dlp\\PC Engine Emulator Full Setup Guide (Ares).mp4')
< /code>
Мне пришлось понизить модуль MoviePy и искать более старую версию ImageMagick, но код все еще не работает. Может ли кто -нибудь помочь мне понять, как успешно объединить видео с субтитрами, используя Python?
log:
Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\Users\User> & C:/Users/User/AppData/Local/Programs/Python/Python310/python.exe c:/yt-dlp/addition_SRT.py
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.2.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to downgrade to 'numpy
Подробнее здесь: https://stackoverflow.com/questions/794 ... gick-pysrt
Проблемы с добавлением субтитров SRT в видео с использованием модулей Python: ImageMagick, Pysrt, MoviePy ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение