使用 MoviePy 时出现类型错误 [英] TypeError when using MoviePy

查看:27
本文介绍了使用 MoviePy 时出现类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试了解 MoviePy 时,我复制了一些示例代码(我稍作修改),从电影文件中剪下 10 秒的部分,在其上叠加文本,然后将其作为不同的文件写入.该代码完美运行......仅适用于某些文件.我有两个视频文件,我想在上面使用代码(仅供练习).两者都是 .mov 文件,都在同一个驱动器上,并且两个路径都是正确的(我已经多次验证它们).问题是我在其中一个文件上遇到了 TypeError,而在另一个文件上却运行良好.代码如下:

In trying to learn a little about MoviePy, I copied some sample code (which I modified slightly) that cuts a 10 second section out of a movie file, overlays text on it, and writes it as a different file. The code works perfectly...only for certain files. I have two video files that I wanted to use the code on (just for practice). Both are .mov files, both are on the same drive and both of the paths are correct (I have verified them multiple times). The problem is I'm getting a TypeError on one of the files while it works perfectly on the other. Here's the code:

from moviepy.editor import *

x = int(input("When do you want the cut to start? "))
y = int(input("When do you want the cut to end? "))


video = VideoFileClip("D:\Videos\Gatlinburgh Drone River 2.MOV").subclip(x,y)

##video = VideoFileClip("D:\SF_ep\T_R_D.mov").subclip(x,y)  #Path is correct


txt_clip = ( TextClip("The Red Dot episode",fontsize=70,color='white')
             .set_position('center')
             .set_duration(10) )

result = CompositeVideoClip([video, txt_clip])

result.write_videofile("Text on Screen.webm",fps=25)

上面的例子很完美.但是,当我将其注释掉并取消注释它下方的视频时,出现以下错误:

The above example works perfectly. However, when I comment it out and uncomment the video right below it, I get the following error:

Traceback (most recent call last):
  File "C:\Users\Sam\Python Projects\MoviePy\Example3c.py", line 15, in <module>
    video = VideoFileClip("D:\\Seinfeld_All_Episodes\\The_Red_Dot.mov").subclip(x,y)
  File "C:\Python34\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 82, in __init__
    nbytes = audio_nbytes)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 63, in __init__
    buffersize=buffersize)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 70, in __init__
    self.buffer_around(1)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 234, in buffer_around
    self.buffer =  self.read_chunk(self.buffersize)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 123, in read_chunk
    self.nchannels))
TypeError: 'float' object cannot be interpreted as an integer

我没有改变任何代码,我只是指向一个不同的文件.我对不同的文件进行了相同的尝试并得到了相同的错误.为什么它适用于一个而不是另一个?有什么想法吗?

I'm not changing any code, I'm just pointing to a different file. I've tried the same with different files and gotten the same error. Why would it work on one and not the other? Any thoughts?

类似问题之前曾被问过 Stack Overflow 但没有任何可靠的答案(在至少没有一个适用于我的特定情况).

A similar question has been asked Stack Overflow before but there weren't any solid answers (at least none that applied to my particular situation).

任何帮助都会很棒.谢谢!

Any help would be great. Thanks!

推荐答案

经过一番搜索,我找到了解决方案 此处.Readers.py 中代码的第 122 行返回的是浮点数而不是整数,因为它使用的是单个/"而不是双//".我改变了那条线,它似乎解决了问题.详情见链接.

After searching around a bit more, I found a solution here. Line 122 of code in Readers.py was returning a float instead of an integer because it was using a single "/" instead of the double "//". I changed that line and it seems to have solved the problem. Details are at the link.

作为记录,我仍然不明白为什么它发生在某些文件而不是其他文件上.然而,修复很简单.

For the record, I still don't understand why it happened on certain files and not others. Nevertheless, the fix was simple.

这篇关于使用 MoviePy 时出现类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆