我的腳本運行的用戶提供了一個文件夾位置和一個文件類型和glob.glob(最簡單的方法),找到該文件所提供的文件類型,並將它們添加到列表中。然後它使用for循環並遍歷列表並轉換每個視頻。但它不喜歡當我嘗試運行我的ffmpeg命令。任何幫助都是極好的。我還使用Win 7的64位與64位的ffmpeg和Python 3.3 這裏的錯誤:與Python回溯錯誤使用時的ffmpeg轉換視頻
OS Error
Traceback (most recent call last):
File "C:\Python33\lib\subprocess.py", line 1106, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\Workspace\PythonConverter\HTMLandPythonConverter\Converter.py", line 77, in <module>
massConvert(fileNames)
File "C:\Users\user\Workspace\PythonConverter\HTMLandPythonConverter\Converter.py", line 47, in massConvert
convertVideotoNewFormat('.mp4', x)
File "C:\Users\user\Workspace\PythonConverter\HTMLandPythonConverter\Converter.py", line 61, in convertVideotoNewFormat
myFile = subprocess.Popen(ffmpegString)#, stdout=subprocess.PIPE, stderr=subprocess.PIPE
File "C:\Python33\lib\subprocess.py", line 820, in __init__
restore_signals, start_new_session)
File "C:\Python33\lib\subprocess.py", line 1112, in _execute_child
raise WindowsError(*e.args)
FileNotFoundError: [WinError 2] The system cannot find the file specified
這裏是我的代碼:
import subprocess
from subprocess import call
import glob
fileNames = []
fileLocation = {}
filetype = {}
def convertString(location):
s = list(location)
for i in range(len(s)):
if s[i] in '\\':
s[i] = '/'
if s[len(s)-1] != '/':
s.append('/')
location = "".join(s)
return location
def convertStringBack(stringTo):
s = list(stringTo)
for i in range(len(s)):
if s[i] in '/':
s[i] = '\\'
stringTo = "".join(s)
return stringTo
def fileTypeTester():
FieldType = '*' + input('What\'s the file type we are converting from?')
typeSplit = list(FieldType)
if typeSplit[1] != '.':
typeSplit.insert(1,'.')
FieldType = "".join(typeSplit)
if FieldType not in ['*.flv','*.kdb']:
print('Not a valid file type')
else:
return FieldType
return None
def massConvert(listOfFiles):
print('Starting Conversion')
for x in listOfFiles:
#x = convertStringBack(x)
print('Converting ' + x + ' to .mp4')
convertVideotoNewFormat('.mp4', x)
print('Finished File Conversion')
def convertVideotoNewFormat(newFormat, fileLoc):
newFilePath = fileLoc[0:len(fileLoc)-4]
ffmpegString = ["ffmpeg64","-i", fileLoc,"-qscale","0","-ar","22050","-vcodec","libx264",newFilePath,newFormat]
try:
subprocess.check_call(newFilePath)
except OSError:
print('OS Error')
except subprocess.CalledProcessError:
print('Subprocess Error')
myFile = subprocess.Popen(ffmpegString)
print(myFile)
#This will replace old HTML flv object tag with new video tag, but it is yet to be implemented
def replaceHTML():
pass
fileLocation = input('What is the path of the files you\'d like to convert?')
fileLocation = convertString(fileLocation)
fileType = fileTypeTester()
fileNames = glob.glob(fileLocation + fileType)
massConvert(fileNames)
我環顧四周,並且大多數教程在2.7的代碼是3.3,我找不到3.3的ffmpeg教程。我的ffmpeg在我的PATH上設置爲'ffmpeg64'。
謝謝!
你_sure_那'ffmpeg64'在你的'PATH'? (你確定你看到的DOS提示符中的'PATH'與Python正在看到的PATH是一樣的嗎?如果你只是在提示符處設置它,它只會影響你的非GUI程序從同一個提示符開始運行。) – abarnert
另外,2.7'子進程'代碼幾乎在3.3中保持不變(只要你不想傳遞非ASCII字符作爲參數,你不會)。所以,你的教程應該沒問題。 – abarnert