SOS,一个有趣的 Python 库

2022-12-13 03:41:47 +08:00
 y4nssss
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
来个大神指点一下吧
1642 次点击
所在节点    问与答
9 条回复
locoz
2022-12-13 03:49:51 +08:00
我的评价是:建议拿着报错内容去咨询 ChatGPT
y4nssss
2022-12-13 03:52:05 +08:00
@locoz 尝试无果
Xs0ul
2022-12-13 04:00:12 +08:00
建议贴上完整的 stack trace 和报错信息。光看你这个报错,看起来像是重复执行某些代码,但没有权限覆盖旧的文件
y4nssss
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
2022-12-13 04:04:44 +08:00
调试:
os.rename(self.getJSONPath(), self.getDir('backup') + os.sep + self.AOBJECT_TYPE() + ".json");
y4nssss
2022-12-13 04:14:13 +08:00
windows 下不行 ubuntu 可以 why??
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
2022-12-13 11:56:36 +08:00
@y4nssss 估计你把 VideoSource.json 这个删掉就可以了。因为什么程序在你脚本运行的时候占用了这个文件,导致你的脚本无法覆盖它。因为 windows 文件打开的时候是更改它的,但 linux 可以。
y4nssss
2022-12-13 11:59:11 +08:00
@craiiz 这个试过了没用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/902082

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX