Below is a list of steps and code modifications that can help you resolve the issues:
1. Install Missing Dependencies
Your log mentions that the module "skimage" is missing. Install scikit-image with:
Also, note the warning regarding NumPy. Either downgrade NumPy to a version below 2.x (for example, 1.23) or upgrade the modules that require NumPy 2 support:
pip install numpy==1.23.5
2. Fix the ImageMagick Issue
By default, MoviePy’s TextClip
uses ImageMagick to create text images. The error
convert.exe: no images defined
suggests that either ImageMagick isn’t installed or MoviePy can’t find it.
You can resolve this in one of two ways:
-
Option A: Install ImageMagick on your computer. Then, make sure its installation path (the directory containing convert.exe) is added to your system’s PATH. Alternatively, set the path in your Python code before creating text clips:
from moviepy.editor import TextClip
TextClip.imagemagick_path = r"C:\Path\to\ImageMagick\convert.exe" # Update with your actual path
-
Option B: Use an alternate text rendering method that doesn’t require ImageMagick by passing a method parameter to TextClip
. For example, using method='caption'
(or sometimes method='label'
) will use PIL instead:
text_clip = TextClip(text, fontsize=24, color='white', font="Arial", method='caption')
3. Improve the Code
Below is an updated version of your code with the fixes and minor improvements (such as replacing newlines and using ordinal values which are sometimes more robust):
from moviepy.editor import VideoFileClip, CompositeVideoClip, TextClip
import pysrt
# (If not using Option B, set the ImageMagick path)
# TextClip.imagemagick_path = r"C:\Path\to\ImageMagick\convert.exe"
# Load video and subtitles
video = VideoFileClip(r"C:\yt-dlp\PC Engine Emulator Full Setup Guide [Ares].webm")
subtitles = pysrt.open(r"C:\yt-dlp\PC Engine Emulator Full Setup Guide [Ares].srt", encoding='utf-8')
subtitle_clips = []
for subtitle in subtitles:
# Replace newline characters in the subtitle text if any
text = subtitle.text.replace("\n", " ")
# Calculate start time and duration using ordinal (milliseconds) for accuracy.
start_time = subtitle.start.ordinal / 1000.0
duration = (subtitle.end.ordinal - subtitle.start.ordinal) / 1000.0
# Create a TextClip using an alternative method to avoid ImageMagick issues:
text_clip = TextClip(text, fontsize=24, color='white', font="Arial", method='caption')
text_clip = text_clip.set_position(('center', 'bottom')) \
.set_start(start_time) \
.set_duration(duration)
subtitle_clips.append(text_clip)
# Composite the video with the subtitle clips.
final_video = CompositeVideoClip([video] + subtitle_clips)
final_video.write_videofile(r'C:\yt-dlp\PC Engine Emulator Full Setup Guide (Ares).mp4', codec="libx264")
Summary
-
Install missing packages:
• Install scikit-image
• Downgrade NumPy if needed
-
Resolve ImageMagick errors:
• Either install and configure ImageMagick correctly or use method='caption'
in TextClip.
-
Update your code:
• Use cleaner time calculations and replace newline characters.
Following these steps should help you combine your videos with subtitles using Python successfully.