繁体   English   中英

带有 concatenate_videoclips 数组的 Moviepy write_videofile 导致 AttributeError

[英]Moviepy write_videofile with Array in concatenate_videoclips results in AttributeError

我尝试编辑一堆视频,为此我将它们从列表中全部写入一个数组,然后使用 concatenate_videoclips 将它们一起编辑为一个。

这似乎有效,但是当我尝试编写此文件时,我从 VideoFileClip.py 收到了一个 AttributeError

这是我尝试过的:

import moviepy.editor as mp

videostoedit = []
currenque = {"File1" : "File1",
             "File2" : "File2",
             "File3" : "File3"}

for z in currentque:
    video = mp.VideoFileClip(z + '/output.mp4')
    videostoedit.append(video)
    video.close()

tempvideo = mp.concatenate_videoclips([i for i in videostoedit], method="compose")
tempvideo.write_videofile('video.mp4', write_logfile=True, fps=60, codec='libx264')
tempvideo.close()

尝试写入临时视频时出现此错误:

t:   0%|                                                                           | 0/21197 [00:00<?, ?it/s, now=None]Traceback (most recent call last):
  File "C:\Users\Username\source\repos\Sandbox\Sandbox\Video.py", line 62, in <module>
    tempvideo.write_videofile(temp_filelocation + '/video.mp4', write_logfile=True, fps=60, codec='libx264')
  File "<C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\decorator.py:decorator-gen-51>", line 2, in write_videofile
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\decorator.py:decorator-gen-50>", line 2, in write_videofile
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\decorator.py:decorator-gen-49>", line 2, in write_videofile
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\video\VideoClip.py", line 326, in write_videofile
    logger=logger)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 216, in ffmpeg_write_video
    fps=fps, dtype="uint8"):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\Clip.py", line 475, in iter_frames
    frame = self.get_frame(t)
  File "<C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\decorator.py:decorator-gen-10>", line 2, in get_frame
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 118, in make_frame
    f = c.blit_on(f, t)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\video\VideoClip.py", line 548, in blit_on
    img = self.get_frame(ct)
  File "<C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\decorator.py:decorator-gen-10>", line 2, in get_frame
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 113, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
AttributeError: 'NoneType' object has no attribute 'get_frame'

这是写操作的错误日志:

ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20181017
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, rawvideo, from 'pipe:':
  Duration: N/A, bitrate: 2985984 kb/s
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1920x1080, 2985984 kb/s, 60 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
[libx264 @ 000001e3144ce300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001e3144ce300] profile High, level 4.2, 4:2:0, 8-bit
[libx264 @ 000001e3144ce300] 264 - core 157 r2935 545de2f - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'Y:/video.mp4':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x1080, q=-1--1, 60 fps, 15360 tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.35.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=    0 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

列表中的所有视频都是由另一个脚本生成的:

    resizedvideo = video.resize((1920,1080))
    resizedvideo.write_videofile(nameoffile, audio='a.mp4', fps=60, codec='libx264', audio_codec='libfdk_aac')

视频都存储在不同的文件夹中,它们的路径在列表中使用唯一的 ID 保存。

此错误的原因可能是什么? 我自己想不通。

我很感激我能得到的所有帮助。

def make_frame(t):
        try:
            x = video_bytes[int(len(video_bytes)/source_duration*t)]
        except:
            x = video_bytes[-1]

        return (x*255).astype(np.uint8)

其中video_bytes是视频的数据,而source_duration是视频的总长度。

暂无
暂无

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

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