標籤:bis bsp lib cpp 尾碼 orb finish == lang
需求: 給定一個檔案夾路徑,遍曆該檔案夾內的所有檔案以及子檔案夾內的檔案,當所有尾碼名為wav格式的檔案轉換為ogg格式的檔案.
import os# 擷取目錄下的所有檔案清單import fnmatch# 檔案格式篩選模組,篩選指定格式檔案- #遍曆
def dirlist(path, allfile): filelist = os.listdir(path)for filename in filelist:filepath = os.path.join(path, filename)if os.path.isdir(filepath):dirlist(filepath, allfile)elif fnmatch.fnmatch(filepath,‘*.wav‘):#判斷檔案格式allfile.append(filepath)#allfile.append(‘\n‘)print(‘*‘*40,filepath,‘\n‘)return allfile
#格式轉換def RunScript(fileList) :print(‘hello world start:‘)readf = open("E:\\py\\readfilename.txt", ‘w+‘) #輸出所有讀入的檔案writef = open("E:\\py\\writefilename.txt", ‘w+‘) #輸出所有建立並寫入的檔案code = "ffmpeg -i "codeMid = " -acodec libvorbis "for filename in fileList:input = filenameprint(‘*‘*40,‘\n‘,‘Begin input = ‘,input,‘\n‘)subname = input.split(‘.‘)output = subname[0] + ".ogg"finishcode = code + input + codeMid + outputos.system(finishcode)print(‘End output = ‘,output,‘\n‘)print(input,file=readf)print(output,file=writef)print(‘hello world end‘)#主程式運行if __name__ ==‘__main__‘:fff = open("E:\\py\\allfile.txt", ‘w+‘) fileDir = r‘G:\SVNworking\trunc\exe\resources\media\audio‘allfile = []dirlist(fileDir,allfile)for name in allfile:print(name,file=fff)RunScript(allfile)
null
使用python+ffmpeg批量轉換格式