1: 장면 소개
M4A 녹음 파일은 일부 장치에서 재생할 수 없으므로 재생하려면 MP3로 변환해야 합니다. 시중에서 판매하는 변환툴을 이용해 적은 양을 기록하는 것은 괜찮지만, 너무 많이 기록하면 문제가 발생하는데, 지금은 15G로 변환할 수 있고, 심지어 수수료를 받는 경우도 있습니다.
2: 도구 준비
1. 여기에 사용된 오픈 소스 FFMPEG 변환, 다운로드 및 설치, 환경 변수 추가
2. Python 3.5 설치 및 환경 변수 추가
3. 개발 도구는 Python에 권장되는 Pycharm입니다.
3: 단점
현재 코드는 멀티스레딩을 사용하지 않으며 상대적으로 느립니다.
4: 코드 시작
여기서는 FFmpeg가 설치되어 있는 경우 작성된 코드를 직접 업로드하겠습니다.
#MA4 to mp3 파일 # _*_ 인코딩:utf-8 _*_ import os import multiprocessing as mp # 파일 열기 fd =open('d:/testerror.txt','w') # 저장 파일 이름 기록 오류 m4a_path = "D:/test file test/test Recording/M4A/" # D:/test file test/test Recording/M4A/Cao Guiyu/" dir_path = "D:/MP3/" #MP3 생성 도로 url = " ffmpeg -i" # 현재 디렉터리의 모든 파일 가져오기 def getALLDir(path,sp = ""): filesList = os.listdir(path) # 각 파일 처리 sp += " " for fileName in filesList: # 파일 여부 판단 연결 방법을 결정하는 디렉터리(절대 경로 사용) 조인입니다. fileAbsPath = os.path.join(path,fileName) if os.path.isdir(fileAbsPath): #Critical 조건: 디렉터리가 아닌 경우 else를 실행합니다. print(sp + "디렉토리 : ",fileName,"======",fileAbsPath) global pathdirsource pathdirsource= dir_path+fileName+"/" print("접속 주소",pathdirsource) mkdir(pathdirsource) getALLDir(fileAbsPath,sp)# 재귀 적으로 자신을 호출합니다. else: # pool.apply_async(doWriteFile,(pathdirsource,fileName,fileAbsPath ) ) )) #fileprocess=Process(target=doWriteFile(pathdirsource,fileName,fileAbsPath)) #fileprocess.start() #print("process id===",fileprocess.pid) doWriteFile(pathdirsource,fileName,fileAbsPath) def doWriteFile ( pathdirsource,fileName,fileAbsPath): try: print("전역 주소",pathdirsource) strpile = 파일 이름[0:-4] str = pathdirsource + "\"" + strpile + "\"" print(url + " " + "\"" + fileAbsPath.replace('\\', '/') + "\""" " + str + ".mp3") str = os.system(url + " " + "\"" + fileAbsPath + "\""" " + str + ".mp3") if str == 1: fd.write(fileAbsPath) # fd.close() print(str, "错误") else: print(str, "====") 제외: print("程序错误===") def mkdir(path): # 去除首位空格 path = 길.Strip() # 후행 \ 기호 제거 path = path.rstrip("\\") # 경로가 존재하는지 확인 # Exists True # 존재하지 않음 False isExists = os.path.exists(path) # isExists가 아닌 경우 판단 결과 : # 디렉터리가 존재하지 않으면 디렉터리를 생성합니다. # 디렉터리 작업 함수를 생성합니다 . os.makedirs(path) print(path,'Created 성공적으로') return True else: # 디렉터리가 존재하면 존재하지 않습니다. 그것을 생성하고, 디렉토리가 생성되었다는 메시지를 표시합니다. Exists print(path + 'Directory 이미 존재합니다') return False if __name__ == '__main__': #프로그램 항목 getALLDir(m4a_path) # 탐색해야 하는 경로