简体   繁体   English

如何在没有 ffmpeg 的情况下将 python 上的视频转换为.mp4?

[英]How to convert video on python to .mp4 without ffmpeg?

I need to convert videos to.mp4 format I used to ffmpeg but it converts for too long.我需要将视频转换为 .mp4 格式,我以前使用过 ffmpeg,但转换时间太长。 Is there are a way to convert video to.mp4 in python without ffmpeg?有没有办法在没有ffmpeg的情况下将python中的视频转换为.mp4?

UPD moviepy depends on ffmpeg too ( UPD moviepy依赖于ffmpeg (

== ==

Zulko/moviepy祖尔科/电影

pip install MoviePy
import moviepy.editor as moviepy
clip = moviepy.VideoFileClip("myvideo.avi")
clip.write_videofile("myvideo.mp4")

As per MoviePy documentation, there is no ffmpeg dependencies:根据MoviePy文档,没有ffmpeg依赖项:

MoviePy depends on the Python modules Numpy , imageio , Decorator , and tqdm , which will be automatically installed during MoviePy's installation. MoviePy 依赖于 Python 模块NumpyimageioDecoratortqdm ,它们将在 MoviePy 安装期间自动安装。

ImageMagick is not strictly required, but needed if you want to incorporate texts. ImageMagick不是严格要求的,但如果您想合并文本则需要。 It can also be used as a backend for GIFs, though you can also create GIFs with MoviePy without ImageMagick.它也可以用作 GIF 的后端,尽管您也可以在没有 ImageMagick 的情况下使用 MoviePy 创建 GIF。

PyGame is needed for video and sound previews (not relevant if you intend to work with MoviePy on a server but essential for advanced video editing by hand). pygame的需要对视频和音频预览(如果你打算用MoviePy工作的服务器上不相关,但必不可少的先进视频手工编辑)。

For advanced image processing, you will need one or several of the following packages:对于高级图像处理,您将需要以下一个或多个软件包:

  • The Python Imaging Library (PIL) or, even better, its branch Pillow . Python Imaging Library (PIL) 或者更好的是它的分支Pillow
  • Scipy (for tracking, segmenting, etc.) can be used to resize video clips if PIL and OpenCV are not installed.如果未安装 PIL 和 OpenCV, Scipy (用于跟踪、分割等)可用于调整视频剪辑的大小。
  • Scikit Image may be needed for some advanced image manipulation.一些高级图像处理可能需要Scikit Image
  • OpenCV 2.4.6 or a more recent version (one that provides the package cv2 ) may be needed for some advanced image manipulation.某些高级图像处理可能需要OpenCV 2.4.6或更新版本(提供包cv2 )。
  • Matplotlib Matplotlib

I wrote a quick program that will convert all video files of a particular type in a directory to another type and put them in another directory.我写了一个快速程序,可以将目录中特定类型的所有视频文件转换为另一种类型,并将它们放在另一个目录中。 I had to install moviepy using Homebrew for it to work rather than rely on PyCharm 's package installation.我必须使用Homebrew安装moviepy才能工作,而不是依赖PyCharm的 package 安装。

import moviepy.editor as moviepy
import os

FROM_EXT    = "mkv"
TO_EXT      = "mp4"
SOURCE_DIR  = "/Volumes/Seagate Media/Movies/MKVs"
DEST_DIR    = "/Volumes/Seagate Media/Movies/MP4s"

for file in os.listdir(SOURCE_DIR):
    if file.lower().endswith(FROM_EXT.lower()):
        from_path   = os.path.join(SOURCE_DIR, file)
        to_path     = os.path.join(DEST_DIR, file.rsplit('.', 1)[0]) + '.' + TO_EXT

        print(f"Converting {from_path} to {to_path}")

        clip = moviepy.VideoFileClip(from_path)
        clip.write_videofile(to_path)

I need to convert videos to .mp4 format I used to ffmpeg but it converts for too long.我需要将视频转换为以前用于ffmpeg的.mp4格式,但转换时间太长。 Is there are a way to convert video to .mp4 in python without ffmpeg?有没有一种方法可以在没有ffmpeg的情况下在python中将视频转换为.mp4?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM