1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| from pathlib import Path import subprocess
input_format = "m4a" output_format = "mp3"
curPath = Path(__file__).parent
input_files = list(curPath.glob(f"*.{input_format}"))
def conversion(input_file: Path): output_filename = f"{input_file.stem}.{output_format}" print(f"[{input_file}] --> [{output_filename}]") process = subprocess.run( [ 'ffmpeg', '-y', '-i', input_file, curPath / output_filename, '-loglevel', 'quiet', ] ) return True if process.returncode == 0 else False
if __name__ == '__main__': for file in input_files: if conversion(file): print("done") else: print("fail!") print("all done")
|
系统中要有ffmpeg
理论上可以修改input_format和output_format来转换别的格式