![](/img/trans.png)
[英]Script works differently when ran from the terminal and ran from Python
[英]Python script doesn't work properly when ran through terminal, but works fine in Jupyter and Visual Studio
我有一個腳本,可以從文件夾中的所有視頻文件中提取音頻。
包含視頻的文件夾位於:/ Users / MyName / Downloads / Video_Audio_files
當我嘗試通過終端運行它並提示folder = input("Path to folder:")
文件夾路徑folder = input("Path to folder:")
,我將其拖放到此處(這是我獲得上述路徑的方式),但是腳本沒有似乎不起作用(卡在7中的0,並且沒有輸出文件)。
當我在Jupyter Notebook或Visual Studio中提示時輸入完全相同的路徑時,它可以完美運行!
編輯:我想我已經找到了問題,當我拖放文件夾時,有一個額外的空間(“下載/文件夾”而不是“下載/文件夾”)。
pbar = ProgressBar()
files = []
extensions = []
folder = input("Path to folder:")
#folder = 'Video_Audio_files'
pathlist = Path(folder).glob('**/*.mp4')
for path in pathlist:
path_in_str = str(path)
name = path_in_str.split("/")[1]
files.append(path_in_str.split(".")[0])
extensions.append(path_in_str.split(".")[1])
os.system('cd ' + folder)
for i in pbar(range(len(files))):
video_format = extensions[i]
video_name = files[i]
output_format = 'flac'
output_name = video_name + '_audio'
bashCommand = 'ffmpeg -i ' + video_name + '.' + video_format + ' -f ' + output_format + ' -ab 192000 -vn ' + output_name + '.' + output_format
#should be of this format: bashCommand = 'ffmpeg -i Video.mp4 -f flac -ab 192000 -vn ExtractedAudio.flac'
os.system(bashCommand)
如編輯中所述找到問題后,我只是實現了以下內容以消除多余的空間:
folder = (input("Path to folder:")[:-1])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.