You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MoviePy启用音频保存视频子片段时出现错误的问题求助

MoviePy启用音频保存视频子片段时出现错误的问题求助

我在尝试用MoviePy处理视频文件、检测场景并保存子片段。当我禁用音频(在write_videofile里设置audio=False)时一切正常,但启用音频后就会出现以下错误:

MoviePy - Writing video new1.mp4
MoviePy - Done !
MoviePy - video ready new1.mp4
Proc not detected chunk: 0%| | 0/388 [00:00<?, ?it/s, now=None]
MoviePy - Writing audio in new2TEMP_MPY_wvf_snd.mp3
Traceback (most recent call last):

MoviePy - Writing audio in new2TEMP_MPY_wvf_snd.mp3
Traceback (most recent call last):
  File "/Users/ahmadnaser/PycharmProjects/Sawt/Frame Detection.py", line 19, in <module>
    SubClip.write_videofile(OutputClip)

以下是我使用的代码:

from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.tools.cuts import detect_scenes

# Load the video and subclip for faster processing
clip = VideoFileClip("/Users/ahmadnaser/Documents/podcast1.mp4").subclip(0, 30)  # Process first 30 seconds
fps = clip.fps

# Detect scenes
SceneTimes = detect_scenes(clip, logger="bar", fps=fps)
FrameChangeTimes = [(float(start), float(end)) for start, end in SceneTimes[0]]

# Process subclips
for i, (start, end) in enumerate(FrameChangeTimes):
    if end - start < 3:  # Skip very short clips
        continue

    SubClip = clip.subclip(start, end)
    OutputClip = f"new{i+1}.mp4"

    # Write the subclip
    SubClip.write_videofile(OutputClip, audio=True)  # Error occurs when audio=True
    SubClip.close()

# Close the main clip
clip.close()

我已经尝试过的方法

  • 设置audio=False可以正常运行,但我需要在输出视频中保留音频。
  • 我已经验证ffmpeg是安装好且可用的,运行ffmpeg -version可以确认它的存在。
  • 用ffprobe确认了源视频包含音频流。

我的环境

  • Python版本:3.9
  • MoviePy版本:1.0.3
  • 操作系统:macOS

问题

为什么启用write_videofile中的音频会导致这个错误?我该如何修复?是我的代码或者设置有特定的问题吗?希望能得到大家的帮助。

备注:内容来源于stack exchange,提问作者Ahmad Naser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:08:02