求助!运行Python File后失败了,FFmpeg安装正确,求原因告知
ffmpeg吧
全部回复
仅看楼主
level 2
_Rovir_ 楼主
这是一个没有封装的软件,作用批量合成已经分割好的视频片段,并配上随机音乐,但是我运行后失败了,FFmpeg安装是正确,求告知原因
代码如下:
import os,sys
import su
bp
rocess
import time
import random
import pathlib
# path = input(r'请输入需要合成的视频目录:')
# pathBgm = input(r'请输入mp3目录:')
# out = input(r'请输入合成后视频存放目录(确保已经创建该目录):')
path = r'D:\1\1'
pathBgm = r'D:\1\BGM'
out = r'D:\1\111'
mp3List = []
videoName = 0
dirs = os.listdir(pathBgm)
for file in dirs:
if file.endswith(".mp3"):
mp3List.append(pathBgm+'\\'+file)
for root,dirs,files in os.walk(path):
for dir in dirs:
#获取目录的路径
path1 = os.path.join(root,dir)
# videoName += 1
for curDir, dirs, files in os.walk(path1):
for file in files:
if file.endswith("list.txt"):
print('当前文件已经存在,删除之后,在进行插入')
os.remove(os.path.join(curDir,"list.txt"))
elif file.endswith("output.mp4"):
os.remove(os.path.join(curDir,"output.mp4"))
else:
print("文件已清理,请系好安全带,开始飙车")
for root,dirs,files in os.walk(path):
for dir in dirs:
#获取目录的路径
path1 = os.path.join(root,dir)
videoName += 1
for curDir, dirs, files in os.walk(path1):
for file in files:
if file.endswith(".mp4"):
with open(os.path.join(curDir,"list.txt"),"a",encoding='utf-8') as f:
_="\nfile '{}'".format(file)
f.write(_)
#下面我们一顿操作
aXiBa1 = "D:\java\bin/ffmpeg -f concat -safe 0 -i {}/list.txt -c copy -an {}/output.mp4".format(path1,path1)
aXiBa2 = 'D:\java\bin/ffmpeg -i {} -i {}/output.mp4 -vcodec copy -acodec copy -shortest -n {}/{}.mp4'.format(random.choice(mp3List),path1,out,videoName)
aoLiGei = subprocess.Popen(aXiBa1, shell=True)
aoLiGei.wait()
aoLiGei2 = subprocess.Popen(aXiBa2, shell=True)
aoLiGei2.wait()
求大佬告知操作步骤,很久没用了,可能哪儿忘记了
2024年03月14日 08点03分 1
level 7
没用过python; 是不是系统目录获取函数返回的是完整路径。二次把自己指定的路径加入了。
建议用相对路径处理
阿西吧1=…… 断点看下是不是加了前面加了两次目录
奥利给.等待 断点看下是不是真的在等待,文件读写速度慢的话几分钟出结果也有可能。
2024年03月15日 06点03分 2
1