I am not a Python expert and all that. I just needed to learn how to combine videos with subtitles, so as not to look for online services for this. I found a simple code for this on the Internet. And I was stunned by how badly it works.
code:
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')
I had to downgrade the moviepy module. Look for an older version of ImageMagick. And other dances with tambourines. In general, this simple code still does not work. Of course, there is a log. Does anyone have any ideas on how to learn to combine videos with subtitles using 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<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "c:\yt-dlp\addition_SRT.py", line 5, in <module>
from moviepy.editor import *
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\editor.py", line 48, in <module>
import moviepy.video.fx.all as vfx
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\video\fx\all\__init__.py", line 17, in <module>
exec("from ..%s import %s" % (name, name))
File "<string>", line 1, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\video\fx\painting.py", line 7, in <module>
from scipy.ndimage.filters import sobel
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\ndimage\__init__.py", line 151, in <module>
from ._filters import * # noqa: F401 F403
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\ndimage\_filters.py", line 37, in <module>
from . import _nd_image
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\video\fx\painting.py", line 4, in <module>
from skimage.filter import sobel
ModuleNotFoundError: No module named 'skimage'
During handling of the above exception, another exception occurred:
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\video\VideoClip.py", line 1137, in __init__
subprocess_call(cmd, logger=None)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\tools.py", line 54, in subprocess_call
raise IOError(err.decode('utf8'))
OSError: convert.exe: no images defined `PNG32:C:\Users\User\AppData\Local\Temp\tmpd840hssd.png' @ error/convert.c/ConvertImageCommand/3322.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\yt-dlp\addition_SRT.py", line 19, in <module>
text_clip = TextClip(text, fontsize=24, color='white', font="Arial")
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\moviepy\video\VideoClip.py", line 1146, in __init__
raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:
convert.exe: no images defined `PNG32:C:\Users\User\AppData\Local\Temp\tmpd840hssd.png' @ error/convert.c/ConvertImageCommand/3322.
.
.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
PS C:\Users\User>