ffmpeg_extract_subclip函数和moviepy字符串输出错误

发布于 2025-01-10 09:19:21 字数 977 浏览 0 评论 0原文

我一直在开发这个小应用程序来下载和剪切 Youtube 视频。 它工作正常,但错误或格式错误的消息是我尚未解决的问题。当谈到切割过程时,使用了函数 ffmpeg_extract_subclip ,在那之后,我得到了下面奇怪的错误: 输入图片这里的描述

下面,脚本运行良好。 输入图片这里的描述

负责剪切视频的函数

# cutting the video by section
def cut_video(video_local_path, start_time, end_time, final_file):

    print("- Cutting your video...")
    ffmpeg_extract_subclip(video_local_path, time_to_sec(start_time), time_to_sec(end_time), targetname=f"{final_file}.mp4")

如有需要可以查看完整代码这里 在 github 上。

我广泛阅读了 ffmpeg 和 moviepy 的 API,在 vscode 上进行了调试,并检查了 VideoFileClip 等替代方案,但它永远不会给我相同的性能。

提前致谢。

I have been developing this small application to download and cut Youtube videos. It works fine but an error or misformatted message is the issue I have not fixed. When it comes to the cutting process, the function ffmpeg_extract_subclip is used and right after that point, I get the weird error below:
enter image description here

Below, the script working fine.
enter image description here

The function responsible for cutting the video

# cutting the video by section
def cut_video(video_local_path, start_time, end_time, final_file):

    print("- Cutting your video...")
    ffmpeg_extract_subclip(video_local_path, time_to_sec(start_time), time_to_sec(end_time), targetname=f"{final_file}.mp4")

If necessary, you can check the full code here on github.

I have extensively read the API for ffmpeg and moviepy, debugged on vscode and checked alternatives like VideoFileClip but it would never give me the same performance.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿看小鸭子会跑 2025-01-17 09:19:21

有几种方法可以解决此问题。

1.暂时重定向 stdout/stderr

请参阅这篇文章

2.直接使用FFmpeg

moviepy< /a> 似乎取决于 imageio-ffmpeg 了解其 FFmpeg 支持,以及 imageio-ffmpegIMAGEIO_FFMPEG_EXE环境路径获取FFmpeg路径安装包时下载FFmpeg可执行文件。因此,您应该能够执行以下操作


import imageio_ffmpeg
import subprocess as sp

ffmpeg_path = imageio_ffmpeg.get_ffmpeg_exe()

sp.run([ffmpeg_path, '-ss', start_time, '-to', end_time, '-i', video_local_path, 
       final_file, '-y'], stderr=sp.NULL, stdout=sp.NULL)

现在,如果您仅将 moviepy 用于此操作(以及其他 FFmpeg 操作),则可以完全删除它并设置 ffmpeg_path到 FFmpeg 路径。 然后通过 ffmpeg-downloader 下载 FFmpeg 二进制文件static-ffmpeg 包。如果您在多个 venv 中使用 FFmpeg,则前者是更好的选择(因为它将 FFmpeg 文件保存在操作系统指定的用户数据区域中,因此只下载一次)。后者是 100% 自动下载方法,与 imageio-ffmpeg 类似,但没有任何多余的装饰

[编辑:imageio-ffmpeg 不会自行下载 FFmpeg,因此您的系统上应该已经有 FFmpeg 可执行文件。]

There are a couple ways to work around this behavior.

1. Momentarily redirect stdout/stderr

See this post

2. Use FFmpeg directly

moviepy appears to be depending on imageio-ffmpeg for its FFmpeg support, and imageio-ffmpeg gets the FFmpeg path from IMAGEIO_FFMPEG_EXE environmental path downloads FFmpeg executables when the package is installed. So, you should be able to do the following


import imageio_ffmpeg
import subprocess as sp

ffmpeg_path = imageio_ffmpeg.get_ffmpeg_exe()

sp.run([ffmpeg_path, '-ss', start_time, '-to', end_time, '-i', video_local_path, 
       final_file, '-y'], stderr=sp.NULL, stdout=sp.NULL)

Now, if you are using moviepy only for this operation (and other FFmpeg operations), you can drop it altogether and set ffmpeg_path to the FFmpeg path. and just download the FFmpeg binaries via ffmpeg-downloader or static-ffmpeg package. The former is a better choice if you use FFmpeg in multiple venvs (as it saves FFmpeg files in an OS designated user data area, so it only downloads once). The latter is 100% automatic downloading approach similar to imageio-ffmpeg but with no frills.

[edit: imageio-ffmpeg does not download FFmpeg on its own, so you should already have the FFmpeg executables on your system.]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文