最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Invalid Font when adding subtitle to video using MoviePy SubtitlesClip (Python) - Stack Overflow

programmeradmin0浏览0评论

here is the part of my script where i used to attach subtitles to video:

def attach_subtitles(video: VideoFileClip) -> None:
    if not os.path.exists(OUTPUT_SRT):
        print("No subtitle file found")
        return

    print("Attaching subtitles to video...")

    # Create subtitle clips
    subtitles = SubtitlesClip(
        OUTPUT_SRT,
        lambda txt: TextClip(
            txt,
            font="Arial",
            fontsize=24,
            color="white",
            bg_color="black",
        )
    )

    # Combine video with subtitles
    video_with_subtitles = CompositeVideoClip(
        [
            video,
            subtitles.with_position(("center", 0.95), relative=True)
        ]
    )

    # Write output video
    print("Rendering final video...")
    video_with_subtitles.write_videofile(
        OUTPUT_VID,
        codec="libx264",
        audio_codec="aac"
    )
    print(f"Video saved as {OUTPUT_VID}")

and i keeps getting this error:

An error occurred: Invalid font <function attach_subtitles.<locals>.<lambda> at 0x00000202C5FCF600>, pillow failed to use it with error 'function' object has no attribute 'read'

i have tried many different fonts but the problem still persists

发布评论

评论列表(0)

  1. 暂无评论