简体   繁体   English

Moviepy 扭曲连接(纵向)视频

[英]Moviepy distorting concatenated (portrait) videos

Trying to concatenate various "Portrait" videos I took with my mobile phone using the moviepy library.尝试使用moviepy库连接我用手机拍摄的各种“肖像”视频。 But for some reason, the result is a distorted video.但由于某种原因,结果是视频失真。 As a TEST CASE, I have even tried to read JUST ONE video clip and re-write it using the concatenate_videoclips method and it still produces a distorted result.作为一个测试案例,我什至尝试读取一个视频剪辑并使用 concatenate_videoclips 方法重新编写它,但它仍然会产生失真的结果。

Here is a sample frame from a test video taken with my mobile (resolution on disk: 1920 x 1080 which obviously includes the black background):这是用我的手机拍摄的测试视频的示例帧(磁盘分辨率:1920 x 1080,显然包括黑色背景):

文本

Here is the same frame captured from the output video (resolution maintained at 1920 x 1080 but without the black background => distorted image):这是从 output 视频中捕获的同一帧(分辨率保持在 1920 x 1080 但没有黑色背景 => 失真图像):

文本

Here is the (very simple) code snippet I used:这是我使用的(非常简单的)代码片段:

from moviepy.editor import VideoFileClip, concatenate_videoclips


video_0 = VideoFileClip("test_vid.mp4")

concatenated_clip = concatenate_videoclips([video_0], method="compose")  # same result if method="chain"
concatenated_clip.write_videofile("test_vid_concat.mp4")

I can't figure out what the issue is.我无法弄清楚问题是什么。

This is a bug in moviepy version 1.0.3 : the ffmpeg reader doesn't take rotation metadata into account for videos captured on phones.这是moviepy版本1.0.3中的一个错误:ffmpeg 阅读器没有考虑手机上捕获的视频的旋转元数据。 The bug was noted in:该错误记录在:

Video file clip width and height do not take rotation metadata into account #1663视频文件剪辑宽度和高度不考虑旋转元数据 #1663

and a fix provided in May of this year on the master branch:以及今年 5 月在master分支上提供的修复:

Take into account rotation metadata to define video size #577考虑旋转元数据来定义视频大小 #577

Version 1.0.3 is still the latest version on PyPI (ie version installed by pip ), so you need to install the master branch ( git clone the repo and run py setup.py install in the source folder) to get the fix. 1.0.3版仍然是 PyPI 上的最新版本(即pip安装的版本),因此您需要安装 master 分支( git clone repo 并在源文件夹中运行py setup.py install )以获取修复。

I ran into the same issue and installing the master branch fixed it for me.我遇到了同样的问题,安装主分支为我修复了它。

Be forewarned: moviepy is still pretty out of date.预先警告: moviepy仍然很过时。 It relies on numpy == 1.20 and so you will have to use a lot of older packages.它依赖于numpy == 1.20 ,因此您将不得不使用许多较旧的软件包。 I highly recommend installing in a virtual environment.我强烈建议安装在虚拟环境中。

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

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