V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
y4nssss
V2EX  ›  问与答

SOS,一个有趣的 Python 库

  •  
  •   y4nssss · 2022-12-13 03:41:47 +08:00 · 1645 次点击
    这是一个创建于 719 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import os
    import time

    import matplotlib
    import matplotlib.pyplot as plt

    import numpy as np
    import visbeat3 as vb

    source_video = vb.PullVideo(name='video', source_location='./data/01.mp4')

    # You can also directly specify an audio
    source_audio = vb.Audio('./data/111.mp3')
    #source_audio = vb.PullVideo(name='audio', source_location='./data/02.mp4')

    synch_video_beat = 0
    synch_audio_beat = 3
    nbeats = 32

    output_path = './result.mp4'

    # If source_audio is from an audio file, use target=source_audio
    warped = vb.Dancify(source_video=source_video,
    target=source_audio.getAudio(),
    synch_video_beat=synch_video_beat,
    synch_audio_beat=synch_audio_beat,
    force_recompute=True,
    warp_type='quad',
    nbeats=nbeats,
    output_path=output_path)


    最后报错:
    FileExistsError: [WinError 183] : './VisBeatAssets/VideoSources\\video\\VideoSource.json' -> './VisBeatAssets/VideoSources\\video\\Data\\Backups\\\\VideoSource.json'

    python 版本:3.8.15
    来个大神指点一下吧
    9 条回复    2022-12-13 11:59:11 +08:00
    locoz
        1
    locoz  
       2022-12-13 03:49:51 +08:00
    我的评价是:建议拿着报错内容去咨询 ChatGPT
    y4nssss
        2
    y4nssss  
    OP
       2022-12-13 03:52:05 +08:00
    @locoz 尝试无果
    Xs0ul
        3
    Xs0ul  
       2022-12-13 04:00:12 +08:00
    建议贴上完整的 stack trace 和报错信息。光看你这个报错,看起来像是重复执行某些代码,但没有权限覆盖旧的文件
    y4nssss
        4
    y4nssss  
    OP
       2022-12-13 04:01:15 +08:00
    D:\tools\anaconda3\envs\pythonProject22\python.exe E:\workspace\pythonProject22\main.py
    destination: ./VisBeatAssets/VideoSources\ name: video source_location: ./data/01.mp4
    Video source at ./VisBeatAssets/VideoSources\video\
    Calculating frames for 01_Full...
    Done.
    Traceback (most recent call last):
    File "E:\workspace\pythonProject22\main.py", line 10, in <module>
    source_video = vb.PullVideo(name='video', source_location='./data/01.mp4')
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\__init__.py", line 59, in PullVideo
    vs = VideoSource.NewVideoSource(destination=GetVideoSourcesDir(), name=vname, source_location=source_location, max_height=max_height, **kwargs);
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 56, in NewVideoSource
    return VideoSource(path=vsdir, name=name, source_location=source_location, **kwargs);
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 45, in __init__
    self.setSource(source_location=source_location, assert_valid=None, **kwargs);
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 499, in setSource
    self.setSourceFile(path = source_location, **kwargs);
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 549, in setSourceFile
    self.addVersion(path=output_path, version_label='Full');
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 477, in addVersion
    self.save();
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 219, in save
    self.hardSave();
    File "D:\tools\anaconda3\envs\pythonProject22\lib\site-packages\visbeat3\VideoSource.py", line 213, in hardSave
    os.rename(self.getJSONPath(), self.getDir('backup') + os.sep + self.AOBJECT_TYPE() + ".json");
    FileExistsError: [WinError 183] 当文件已存在时,无法创建该文件。: './VisBeatAssets/VideoSources\\video\\VideoSource.json' -> './VisBeatAssets/VideoSources\\video\\Data\\Backups\\\\VideoSource.json'

    进程已结束,退出代码 1
    y4nssss
        5
    y4nssss  
    OP
       2022-12-13 04:04:44 +08:00
    调试:
    os.rename(self.getJSONPath(), self.getDir('backup') + os.sep + self.AOBJECT_TYPE() + ".json");
    y4nssss
        6
    y4nssss  
    OP
       2022-12-13 04:14:13 +08:00
    windows 下不行 ubuntu 可以 why??
    Xs0ul
        7
    Xs0ul  
       2022-12-13 04:21:30 +08:00
    https://docs.python.org/3/library/os.html

    On Windows, if dst exists a FileExistsError is always raised.
    On Unix, ... If both are files, dst will be replaced silently if the user has permission.
    craiiz
        8
    craiiz  
       2022-12-13 11:56:36 +08:00
    @y4nssss 估计你把 VideoSource.json 这个删掉就可以了。因为什么程序在你脚本运行的时候占用了这个文件,导致你的脚本无法覆盖它。因为 windows 文件打开的时候是更改它的,但 linux 可以。
    y4nssss
        9
    y4nssss  
    OP
       2022-12-13 11:59:11 +08:00
    @craiiz 这个试过了没用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2718 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:23 · PVG 17:23 · LAX 01:23 · JFK 04:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.